Package net.imglib2.parallel
Class TaskExecutors
- java.lang.Object
-
- net.imglib2.parallel.TaskExecutors
-
public final class TaskExecutors extends java.lang.ObjectUtility class, with methods to createTaskExecutors.
-
-
Field Summary
Fields Modifier and Type Field Description private static TaskExecutorFORK_JOIN_TASK_EXECUTOR
-
Constructor Summary
Constructors Modifier Constructor Description privateTaskExecutors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.concurrent.ThreadFactoryapplyTaskExecutorToThreadFactory(java.util.function.Supplier<TaskExecutor> taskExecutorFactory, java.util.concurrent.ThreadFactory threadFactory)Returns aThreadFactory.static TaskExecutorfixedThreadPool(int numThreads)Returns aTaskExecutorthat uses a fixed thread pool with the given number of threads.static TaskExecutorforExecutorService(java.util.concurrent.ExecutorService executorService)Creates aTaskExecutorthat wraps around givenExecutorService.static TaskExecutorforExecutorServiceAndNumTasks(java.util.concurrent.ExecutorService executorService, int numTasks)Creates aTaskExecutorthat wraps around givenExecutorService, and will suggest the given number of tasks when asked.static TaskExecutorforExecutorServiceAndNumThreads(java.util.concurrent.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 java.util.concurrent.ThreadFactorythreadFactory(java.util.function.Supplier<TaskExecutor> taskExecutorFactory)Returns aThreadFactory.
-
-
-
Field Detail
-
FORK_JOIN_TASK_EXECUTOR
private static final TaskExecutor FORK_JOIN_TASK_EXECUTOR
-
-
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(java.util.concurrent.ExecutorService executorService)
Creates aTaskExecutorthat wraps around givenExecutorService.
-
forExecutorServiceAndNumThreads
public static TaskExecutor forExecutorServiceAndNumThreads(java.util.concurrent.ExecutorService executorService, int numThreads)
Creates aTaskExecutorthat wraps around givenExecutorService, and will return the given parallelism.
-
forExecutorServiceAndNumTasks
public static TaskExecutor forExecutorServiceAndNumTasks(java.util.concurrent.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 java.util.concurrent.ThreadFactory threadFactory(java.util.function.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 java.util.concurrent.ThreadFactory applyTaskExecutorToThreadFactory(java.util.function.Supplier<TaskExecutor> taskExecutorFactory, java.util.concurrent.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.
-
-