Class TaskExecutors
java.lang.Object
net.imglib2.parallel.TaskExecutors
Utility class, with methods to create
TaskExecutors.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 TaskExecutorTaskExecutorfor 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 TaskExecutorTaskExecutorfor single threaded execution.static ThreadFactorythreadFactory(Supplier<TaskExecutor> taskExecutorFactory) Returns aThreadFactory.
-
Field Details
-
FORK_JOIN_TASK_EXECUTOR
-
-
Constructor Details
-
TaskExecutors
private TaskExecutors()
-
-
Method Details
-
singleThreaded
TaskExecutorfor single threaded execution. -
multiThreaded
TaskExecutorfor multi-threaded execution.ForkJoinPoolis used. -
numThreads
TaskExecutorthat uses the given number or threads. TheTaskExecutorneeds to be closed by callingTaskExecutor.close(). -
forExecutorService
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
Returns aTaskExecutorthat uses a fixed thread pool with the given number of threads. -
nestedFixedThreadPool
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
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.
-