Class Executors

java.lang.Object
java.util.concurrent.Executors

public class Executors extends Object

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 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)