- java.lang.Object
-
- org.scijava.concurrent.TaskExecutors
-
public final class TaskExecutors extends Object
Utility class, with methods to createTaskExecutors.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ThreadFactoryapplyTaskExecutorToThreadFactory(Supplier<TaskExecutor> taskExecutorFactory, ThreadFactory threadFactory)Returns aThreadFactory.static TaskExecutorfixedThreadPool(int numThreads)Returns aTaskExecutorthat uses a fixed thread pool with the given number of threads.static TaskExecutorforExecutorService(ExecutorService executorService)Creates aTaskExecutorthat wraps around givenExecutorService.static TaskExecutorforExecutorServiceAndNumTasks(ExecutorService executorService, int numTasks)Creates aTaskExecutorthat wraps around givenExecutorService, and will suggest the given number of tasks when asked.static TaskExecutorforExecutorServiceAndNumThreads(ExecutorService executorService, int numThreads)Creates aTaskExecutorthat wraps around givenExecutorService, and will return the given parallelism.static TaskExecutormultiThreaded()TaskExecutorfor multi-threaded execution.static TaskExecutornestedFixedThreadPool(int numThreads, int numSubThreads)Returns aTaskExecutorthat uses a fixed thread pool with the given number of threads.static TaskExecutornumThreads(int numThreads)TaskExecutorthat uses the given number or threads.static TaskExecutorsingleThreaded()TaskExecutorfor single threaded execution.static ThreadFactorythreadFactory(Supplier<TaskExecutor> taskExecutorFactory)Returns aThreadFactory.
-
-
-
Method Detail
-
singleThreaded
public static TaskExecutor singleThreaded()
TaskExecutorfor single threaded execution.
-
multiThreaded
public static TaskExecutor multiThreaded()
TaskExecutorfor multi-threaded execution.ForkJoinPoolis used.
-
numThreads
public static TaskExecutor numThreads(int numThreads)
TaskExecutorthat uses the given number or threads. TheTaskExecutorneeds to be closed by callingTaskExecutor.close().
-
forExecutorService
public static TaskExecutor forExecutorService(ExecutorService executorService)
Creates aTaskExecutorthat wraps around givenExecutorService.
-
forExecutorServiceAndNumThreads
public static TaskExecutor forExecutorServiceAndNumThreads(ExecutorService executorService, int numThreads)
Creates aTaskExecutorthat wraps around givenExecutorService, and will return the given parallelism.
-
forExecutorServiceAndNumTasks
public static TaskExecutor forExecutorServiceAndNumTasks(ExecutorService executorService, int numTasks)
Creates aTaskExecutorthat wraps around givenExecutorService, and will suggest the given number of tasks when asked.
-
fixedThreadPool
public static TaskExecutor fixedThreadPool(int numThreads)
Returns aTaskExecutorthat uses a fixed thread pool with the given number of threads.
-
nestedFixedThreadPool
public static TaskExecutor nestedFixedThreadPool(int numThreads, int numSubThreads)
Returns aTaskExecutorthat 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
TaskExecutoris useful for nested parallelization, when detailed control for the level of parallelism is needed.
-
threadFactory
public static ThreadFactory threadFactory(Supplier<TaskExecutor> taskExecutorFactory)
Returns aThreadFactory. Whenever this thread factory is used to create a thread, aTaskExecutorwill is create and assigned to the thread. TheTaskExecutoris created using the given supplier.
-
applyTaskExecutorToThreadFactory
public static ThreadFactory applyTaskExecutorToThreadFactory(Supplier<TaskExecutor> taskExecutorFactory, ThreadFactory threadFactory)
Returns aThreadFactory. Whenever this thread factory is used to create a thread, aTaskExecutorwill is create and assigned to the thread. The threads created, are using the given thread factory, and theTaskExecutorsare create using the given supplier.
-
-