Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public class Executors

  1. Object
  2. 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.

Methods

public static ExecutorService newFixedThreadPool(int nThreads)
public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory)
public static ExecutorService newSingleThreadExecutor()
public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory)
public static ExecutorService newCachedThreadPool()
public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory)
public static ExecutorService newWorkStealingPool()A pool for work that splits itself up: here, a fixed pool.
public static ExecutorService newWorkStealingPool(int parallelism)
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize)
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.
public static ScheduledExecutorService newSingleThreadScheduledExecutor()
public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory)
public static ThreadFactory defaultThreadFactory()The factory the executors use by default: non-daemon threads named pool-N-thread-M.
public static <T> Callable<T> callable(Runnable task, T result)A Callable that runs task and answers result.
public static Callable<Object> callable(Runnable task)

Inherited methods

Method details

newFixedThreadPool

public static ExecutorService newFixedThreadPool(int nThreads)

newFixedThreadPool

public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory)

newSingleThreadExecutor

public static ExecutorService newSingleThreadExecutor()

newSingleThreadExecutor

public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory)

newCachedThreadPool

public static ExecutorService newCachedThreadPool()

newCachedThreadPool

public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory)

newWorkStealingPool

public static ExecutorService newWorkStealingPool()
A pool for work that splits itself up: here, a fixed pool.

newWorkStealingPool

public static ExecutorService newWorkStealingPool(int parallelism)

newScheduledThreadPool

public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize)

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

public static ScheduledExecutorService newSingleThreadScheduledExecutor()

newSingleThreadScheduledExecutor

public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory)

defaultThreadFactory

public static ThreadFactory defaultThreadFactory()
The factory the executors use by default: non-daemon threads named pool-N-thread-M.

callable

public static <T> Callable<T> callable(Runnable task, T result)
A Callable that runs task and answers result.

callable

public static Callable<Object> callable(Runnable task)