Class TaskExecutors


  • public final class TaskExecutors
    extends java.lang.Object
    Utility class, with methods to create TaskExecutors.
    • Field Detail

      • FORK_JOIN_TASK_EXECUTOR

        private static final TaskExecutor FORK_JOIN_TASK_EXECUTOR
    • Constructor Detail

      • TaskExecutors

        private TaskExecutors()
    • Method Detail

      • multiThreaded

        public static TaskExecutor multiThreaded()
        TaskExecutor for multi-threaded execution. ForkJoinPool is used.
      • forExecutorService

        public static TaskExecutor forExecutorService​(java.util.concurrent.ExecutorService executorService)
        Creates a TaskExecutor that wraps around given ExecutorService.
      • forExecutorServiceAndNumThreads

        public static TaskExecutor forExecutorServiceAndNumThreads​(java.util.concurrent.ExecutorService executorService,
                                                                   int numThreads)
        Creates a TaskExecutor that wraps around given ExecutorService, and will return the given parallelism.
      • forExecutorServiceAndNumTasks

        public static TaskExecutor forExecutorServiceAndNumTasks​(java.util.concurrent.ExecutorService executorService,
                                                                 int numTasks)
        Creates a TaskExecutor that wraps around given ExecutorService, and will suggest the given number of tasks when asked.
      • fixedThreadPool

        public static TaskExecutor fixedThreadPool​(int numThreads)
        Returns a TaskExecutor that uses a fixed thread pool with the given number of threads.
      • nestedFixedThreadPool

        public static TaskExecutor nestedFixedThreadPool​(int numThreads,
                                                         int numSubThreads)
        Returns a TaskExecutor that uses a fixed thread pool with the given number of threads. But that's not the end of the story.

        Each of the threads uses itself a fixed thread pool with the given number of sub threads.

        This TaskExecutor is useful for nested parallelization, when detailed control for the level of parallelism is needed.

      • threadFactory

        public static java.util.concurrent.ThreadFactory threadFactory​(java.util.function.Supplier<TaskExecutor> taskExecutorFactory)
        Returns a ThreadFactory. Whenever this thread factory is used to create a thread, a TaskExecutor will is create and assigned to the thread. The TaskExecutor is created using the given supplier.
      • applyTaskExecutorToThreadFactory

        public static java.util.concurrent.ThreadFactory applyTaskExecutorToThreadFactory​(java.util.function.Supplier<TaskExecutor> taskExecutorFactory,
                                                                                          java.util.concurrent.ThreadFactory threadFactory)
        Returns a ThreadFactory. Whenever this thread factory is used to create a thread, a TaskExecutor will is create and assigned to the thread. The threads created, are using the given thread factory, and the TaskExecutors are create using the given supplier.