public class DefaultTaskExecutor extends Object implements TaskExecutor
TaskExecutor
that wraps around a given ExecutorService
.Constructor and Description |
---|
DefaultTaskExecutor(ExecutorService executorService) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
<T> void |
forEach(List<? extends T> parameters,
Consumer<? super T> task)
Like
TaskExecutor.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)
Like
TaskExecutor.forEach(List, Consumer) but collects the results. |
ExecutorService |
getExecutorService()
Get the underlying
ExecutorService . |
int |
getParallelism()
Get the number of threads that are used for execution.
|
void |
runAll(List<Runnable> tasks)
This method will execute the given list of tasks.
|
int |
suggestNumberOfTasks()
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.
|
public DefaultTaskExecutor(ExecutorService executorService)
public ExecutorService getExecutorService()
TaskExecutor
ExecutorService
. This is not always a
fully functional ExecutorService
: Especially the methods
ExecutorService.shutdown()
and
ExecutorService.awaitTermination(long, TimeUnit)
must not be
used.getExecutorService
in interface TaskExecutor
public int getParallelism()
TaskExecutor
getParallelism
in interface TaskExecutor
public void runAll(List<Runnable> tasks)
TaskExecutor
TaskExecutor
will execute the tasks one after the
other. A multi threaded TaskExecutor
will distribute the
tasks to the threads. The method blocks until all tasks are completed.runAll
in interface TaskExecutor
public int suggestNumberOfTasks()
TaskExecutor
A single threaded TaskExecutor
will return 1.
A multi threaded TaskExecutor
will usually return 4 times
the number of threads.
suggestNumberOfTasks
in interface TaskExecutor
public <T> void forEach(List<? extends T> parameters, Consumer<? super T> task)
TaskExecutor
TaskExecutor.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.forEach
in interface TaskExecutor
public <T,R> List<R> forEachApply(List<? extends T> parameters, Function<? super T,? extends R> task)
TaskExecutor
TaskExecutor.forEach(List, Consumer)
but collects the results.forEachApply
in interface TaskExecutor
public void close()
close
in interface AutoCloseable
close
in interface TaskExecutor
Copyright © 2015–2022 ImgLib2. All rights reserved.