T - type of value to operate onpublic final class Paralleler<T> extends Object
A convenient way of executing a large number of small tasks in parallel. The values to be operated on
are provided as an Iterator over values, along with a function that does something to each value,
as a Processor.
By default the work is performed on each value in a number of threads equal to the number of cores on the
machines, when calling runInParallel(). The operations may also be invoked with a given
ExecutorService and parallelism with runInParallel(ExecutorService, int).
| Constructor and Description |
|---|
Paralleler(Iterator<T> values,
Processor<T> processor)
Creates an instance which will apply a
Processor to many values. |
Paralleler(Iterator<T> values,
Processor<T> processor,
String name)
Creates an instance which will apply a
Processor to many values. |
| Modifier and Type | Method and Description |
|---|---|
void |
runInParallel()
Run
Processor, in as many threads as available cores, on values. |
void |
runInParallel(ExecutorService executor,
int parallelism)
Run
Processor, in as many threads as available cores, on values. |
void |
runInSerial()
Run
Processor, but only in 1 thread, on values. |
public Paralleler(Iterator<T> values, Processor<T> processor)
Processor to many values.values - values to be processed with processorprocessor - Processor to apply to each valuepublic void runInSerial()
throws ExecutionException
Processor, but only in 1 thread, on values.ExecutionException - if any execution failspublic void runInParallel()
throws InterruptedException,
ExecutionException
Processor, in as many threads as available cores, on values.ExecutionException - if any execution failsInterruptedExceptionpublic void runInParallel(ExecutorService executor, int parallelism) throws InterruptedException, ExecutionException
Processor, in as many threads as available cores, on values. The given
ExecutorService and number of threads are used instead of a new one.ExecutionException - if any execution failsInterruptedExceptionCopyright © 2012-2013 Myrrix Ltd. All Rights Reserved.