Class DefaultTaskExecutor
java.lang.Object
net.imglib2.parallel.DefaultTaskExecutor
- All Implemented Interfaces:
AutoCloseable, TaskExecutor
A
TaskExecutor that wraps around a given ExecutorService.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()private <T> T[]concatenate(T[] a, T[] b) <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.intGet the number of threads that are used for execution.private voidinvokeAllIgnoreResults(List<Callable<Object>> callables) 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.private RuntimeExceptionExecutorServicewrap all exceptions thrown by any task into aExecutionException, this makes the stack traces rather hard to read.
-
Field Details
-
executorService
-
-
Constructor Details
-
DefaultTaskExecutor
-
-
Method Details
-
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
-
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
-
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
-
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
-
invokeAllIgnoreResults
-
unwrapExecutionException
ExecutorServicewrap all exceptions thrown by any task into aExecutionException, this makes the stack traces rather hard to read. This method unwraps theExecutionExceptionand thereby reveals the original exception, and ensures it's complete stack trace. -
concatenate
private <T> T[] concatenate(T[] a, T[] b) -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTaskExecutor
-