|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apfloat.internal.ParallelRunner
public class ParallelRunner
Class for running Runnable objects in parallel using multiple threads.
The general paradigm for executing parallel tasks is:
ParallelRunner parallelRunner = new ParallelRunner(numberOfProcessors); parallelRunner.lock(key); try { parallelRunner.runParallel(parallelRunnable1); parallelRunner.runParallel(parallelRunnable2); parallelRunner.runParallel(parallelRunnable3); } finally { parallelRunner.unlock(); }The
key
is any object that is used to determine distinct
groups for the synchronization. For example, the shared memory lock
object from ApfloatContext.getSharedMemoryLock()
can be used
to limit memory consumption when the shared memory treshold is exceeded.
To avoid any blocking due to synchronization, a ParallelRunner
can also be used without calling the lock(Object)
and unlock()
methods.
Constructor Summary | |
---|---|
ParallelRunner(int numberOfProcessors)
Create an instance of a parallel runner. |
Method Summary | |
---|---|
void |
lock(Object key)
Start the synchronization for the given lock key. |
void |
runParallel(ParallelRunnable parallelRunnable)
Run Runnable objects in parallel. |
void |
unlock()
Finish the synchronization. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ParallelRunner(int numberOfProcessors)
numberOfProcessors
- The number of parallel threads to use.Method Detail |
---|
public void lock(Object key)
unlock()
method,
in the finally
block of the immediately following
try
block, just like for concurrency locks.
key
- The lock key for synchronization.public void unlock()
lock(Object)
method.
public void runParallel(ParallelRunnable parallelRunnable) throws ApfloatRuntimeException
lock(Object)
method with the same key
. The Runnables
for processing the strides are run using the ExecutorService retrieved from
ApfloatContext.getExecutorService()
.
parallelRunnable
- The ParallelRunnable containing the Runnable objects to be run.
ApfloatRuntimeException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |