Package net.imglib2.parallel
Class SequentialTaskExecutor
- java.lang.Object
-
- net.imglib2.parallel.SequentialTaskExecutor
-
- All Implemented Interfaces:
java.lang.AutoCloseable,TaskExecutor
class SequentialTaskExecutor extends java.lang.Object implements TaskExecutor
ATaskExecutorfor single threaded execution.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ExecutorServiceexecutorServiceprivate static SequentialTaskExecutorINSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description privateSequentialTaskExecutor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()<T> voidforEach(java.util.List<? extends T> parameters, java.util.function.Consumer<? super T> task)LikeTaskExecutor.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>
java.util.List<R>forEachApply(java.util.List<? extends T> parameters, java.util.function.Function<? super T,? extends R> task)LikeTaskExecutor.forEach(List, Consumer)but collects the results.java.util.concurrent.ExecutorServicegetExecutorService()Get the underlyingExecutorService.static TaskExecutorgetInstance()intgetParallelism()Get the number of threads that are used for execution.voidrunAll(java.util.List<java.lang.Runnable> tasks)This method will execute the given list of tasks.intsuggestNumberOfTasks()If 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 Detail
-
INSTANCE
private static final SequentialTaskExecutor INSTANCE
-
executorService
private final java.util.concurrent.ExecutorService executorService
-
-
Method Detail
-
getInstance
public static TaskExecutor getInstance()
-
getExecutorService
public java.util.concurrent.ExecutorService 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
public void runAll(java.util.List<java.lang.Runnable> tasks)
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
public <T> void forEach(java.util.List<? extends T> parameters, java.util.function.Consumer<? super T> task)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> java.util.List<R> forEachApply(java.util.List<? extends T> parameters, java.util.function.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 interfacejava.lang.AutoCloseable- Specified by:
closein interfaceTaskExecutor
-
-