Author: rwhitcomb
Date: Thu Dec  7 17:57:51 2017
New Revision: 1817402

URL: http://svn.apache.org/viewvc?rev=1817402&view=rev
Log:
PIVOT-498:  Make the default executor service for Task, TaskSequence, and
TaskGroup into an "Executors.newCachedThreadPool()", instead of our simple
service, which was created as a workaround for some problems seen ~7-8
years ago.
Move that "DefaultExecutorService" out to its own "SimpleExecutorService"
class, so it can still be used as a workaround if necessary.

Added:
    
pivot/trunk/core/src/org/apache/pivot/util/concurrent/SimpleExecutorService.java
Modified:
    pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java

Added: 
pivot/trunk/core/src/org/apache/pivot/util/concurrent/SimpleExecutorService.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/concurrent/SimpleExecutorService.java?rev=1817402&view=auto
==============================================================================
--- 
pivot/trunk/core/src/org/apache/pivot/util/concurrent/SimpleExecutorService.java
 (added)
+++ 
pivot/trunk/core/src/org/apache/pivot/util/concurrent/SimpleExecutorService.java
 Thu Dec  7 17:57:51 2017
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.util.concurrent;
+
+import java.util.concurrent.AbstractExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * An executor service that simply spawns a new thread on every call to {@link 
#execute}.
+ * <p> Note: this has been moved out of {@link Task} where it used to be used 
as the default
+ * executor service as a workaround for problems seen some time ago with
+ * {@link java.util.concurrent.Executors#newCachedThreadPool} when running as 
an applet.
+ * <p> The default for {@link Task}, {@link TaskSequence} and {@link 
TaskGroup} is now to
+ * use the system service, but this class may be used still as a workaround if 
problems
+ * are still seen (unlikely).
+ */
+public class SimpleExecutorService extends AbstractExecutorService {
+    private boolean shutdown = false;
+
+    @Override
+    public boolean awaitTermination(long timeout, TimeUnit unit) throws 
InterruptedException {
+        return true;
+    }
+
+    @Override
+    public void shutdown() {
+        shutdownNow();
+    }
+
+    @Override
+    public java.util.List<Runnable> shutdownNow() {
+        shutdown = true;
+        return new java.util.ArrayList<>();
+    }
+
+    @Override
+    public boolean isShutdown() {
+        return shutdown;
+    }
+
+    @Override
+    public boolean isTerminated() {
+        return isShutdown();
+    }
+
+    @Override
+    public void execute(Runnable command) {
+        Thread thread = new Thread(command);
+        thread.start();
+    }
+}
+

Modified: pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java?rev=1817402&r1=1817401&r2=1817402&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/concurrent/Task.java Thu Dec  7 
17:57:51 2017
@@ -17,9 +17,8 @@
 package org.apache.pivot.util.concurrent;
 
 import java.lang.ref.WeakReference;
-import java.util.concurrent.AbstractExecutorService;
+import java.util.concurrent.Executors;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.pivot.util.Utils;
 
@@ -69,42 +68,6 @@ public abstract class Task<V> {
         }
     }
 
-    private static class DefaultExecutorService extends 
AbstractExecutorService {
-        private boolean shutdown = false;
-
-        @Override
-        public boolean awaitTermination(long timeout, TimeUnit unit) throws 
InterruptedException {
-            return true;
-        }
-
-        @Override
-        public void shutdown() {
-            shutdownNow();
-        }
-
-        @Override
-        public java.util.List<Runnable> shutdownNow() {
-            shutdown = true;
-            return new java.util.ArrayList<>();
-        }
-
-        @Override
-        public boolean isShutdown() {
-            return shutdown;
-        }
-
-        @Override
-        public boolean isTerminated() {
-            return isShutdown();
-        }
-
-        @Override
-        public void execute(Runnable command) {
-            Thread thread = new Thread(command);
-            thread.start();
-        }
-    }
-
     private ExecutorService executorService;
 
     private V result = null;
@@ -115,10 +78,7 @@ public abstract class Task<V> {
     protected volatile long timeout = Long.MAX_VALUE;
     protected volatile boolean abort = false;
 
-    // TODO This is a workaround for an issue with
-    // Executors.newCachedThreadPool(), which
-    // unpredictably throws IllegalThreadStateException when run in an applet.
-    public static final ExecutorService DEFAULT_EXECUTOR_SERVICE = new 
DefaultExecutorService();
+    public static final ExecutorService DEFAULT_EXECUTOR_SERVICE = 
Executors.newCachedThreadPool();
 
     public Task() {
         this(DEFAULT_EXECUTOR_SERVICE);


Reply via email to