Class Executors
java.lang.Object
java.util.concurrent.Executors
Factories for the executor services.
Where a task runs
On the pool's own threads, never on the UI thread. A task that touches
the user interface hands that part back, the way desktop code does with
SwingUtilities.invokeLater or Platform.runLater.
Workers are started when a task first needs one and share one queue: a
task goes to whichever worker is free. A fixed pool keeps its workers
until it is shut down; a cached pool starts one whenever none is free and
lets one go after a minute without work, as the JDK's do. The overloads
that take a ThreadFactory make their workers with it.
Waiting
Future.get() and awaitTermination on the UI thread wait through
JdkHost.blockUi, so events keep being dispatched.
The work stealing pools are fixed pools.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Callable<T> ACallablethat runstaskand answersresult.static ThreadFactoryThe factory the executors use by default: non-daemon threads namedpool-N-thread-M.static ExecutorServicestatic ExecutorServicenewCachedThreadPool(ThreadFactory threadFactory) static ExecutorServicenewFixedThreadPool(int nThreads) static ExecutorServicenewFixedThreadPool(int nThreads, ThreadFactory threadFactory) static ScheduledExecutorServicenewScheduledThreadPool(int corePoolSize) static ScheduledExecutorServicenewScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory) Zero is accepted, as the JDK accepts it: a zero sized scheduled pool still starts a worker for the first task it is given.static ExecutorServicestatic ExecutorServicenewSingleThreadExecutor(ThreadFactory threadFactory) static ScheduledExecutorServicestatic ScheduledExecutorServicenewSingleThreadScheduledExecutor(ThreadFactory threadFactory) static ExecutorServiceA pool for work that splits itself up: here, a fixed pool.static ExecutorServicenewWorkStealingPool(int parallelism)
-
Method Details
-
newFixedThreadPool
-
newFixedThreadPool
-
newSingleThreadExecutor
-
newSingleThreadExecutor
-
newCachedThreadPool
-
newCachedThreadPool
-
newWorkStealingPool
A pool for work that splits itself up: here, a fixed pool. -
newWorkStealingPool
-
newScheduledThreadPool
-
newScheduledThreadPool
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory) Zero is accepted, as the JDK accepts it: a zero sized scheduled pool still starts a worker for the first task it is given. -
newSingleThreadScheduledExecutor
-
newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory) -
defaultThreadFactory
The factory the executors use by default: non-daemon threads namedpool-N-thread-M. -
callable
-
callable
-