Class SequentialTaskExecutor
java.lang.Object
net.imglib2.parallel.SequentialTaskExecutor
- All Implemented Interfaces:
AutoCloseable, TaskExecutor
A
TaskExecutor for single threaded execution.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ExecutorServiceprivate static final SequentialTaskExecutor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()<T> voidLikeTaskExecutor.runAll(List)but - instead of a list of tasks - it takes a list of parameters and a function that is called for each of the parameters.<T,R> List <R> forEachApply(List<? extends T> parameters, Function<? super T, ? extends R> task) LikeTaskExecutor.forEach(List, Consumer)but collects the results.Get the underlyingExecutorService.static TaskExecutorintGet the number of threads that are used for execution.voidThis method will execute the given list of tasks.intIf there is a big task that could be split into sub tasks for parallelization, this method gives you a reasonable number of sub tasks.
-
Field Details
-
INSTANCE
-
executorService
-
-
Constructor Details
-
SequentialTaskExecutor
private SequentialTaskExecutor()
-
-
Method Details
-
getInstance
-
getExecutorService
Description copied from interface:TaskExecutorGet the underlyingExecutorService. This is not always a fully functionalExecutorService: Especially the methodsExecutorService.shutdown()andExecutorService.awaitTermination(long, TimeUnit)must not be used.- Specified by:
getExecutorServicein interfaceTaskExecutor
-
suggestNumberOfTasks
public int suggestNumberOfTasks()Description copied from interface:TaskExecutorIf there is a big task that could be split into sub tasks for parallelization, this method gives you a reasonable number of sub tasks.A single threaded
TaskExecutorwill return 1. A multi threadedTaskExecutorwill usually return 4 times the number of threads.- Specified by:
suggestNumberOfTasksin interfaceTaskExecutor
-
getParallelism
public int getParallelism()Description copied from interface:TaskExecutorGet the number of threads that are used for execution.- Specified by:
getParallelismin interfaceTaskExecutor
-
runAll
Description copied from interface:TaskExecutorThis method will execute the given list of tasks. A single threadedTaskExecutorwill execute the tasks one after the other. A multi threadedTaskExecutorwill distribute the tasks to the threads. The method blocks until all tasks are completed.- Specified by:
runAllin interfaceTaskExecutor
-
forEach
Description copied from interface:TaskExecutorLikeTaskExecutor.runAll(List)but - instead of a list of tasks - it takes a list of parameters and a function that is called for each of the parameters.- Specified by:
forEachin interfaceTaskExecutor
-
forEachApply
public <T,R> List<R> forEachApply(List<? extends T> parameters, Function<? super T, ? extends R> task) Description copied from interface:TaskExecutorLikeTaskExecutor.forEach(List, Consumer)but collects the results.- Specified by:
forEachApplyin interfaceTaskExecutor
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTaskExecutor
-