|
|||||||||
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:
lock(key, numberOfProcessors); try { runParallel(key, parallelRunnable1); runParallel(key, parallelRunnable2); runParallel(key, parallelRunnable3); } finally { unlock(key); }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 new Object()
can be used as the key.
Method Summary | |
---|---|
static void |
lock(Object key,
int numberOfProcessors)
Start the synchronization for the given lock key. |
static void |
runParallel(Object key,
ParallelRunnable parallelRunnable)
Run Runnable objects in parallel. |
static void |
unlock(Object key)
Finish the synchronization for the given lock key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void lock(Object key, int numberOfProcessors)
unlock(Object)
method,
in the finally
block of the immediately following
try
block, just like for concurrency locks.
key
- The lock key for synchronization.numberOfProcessors
- The number of parallel threads to contribute to the parallel processing.public static void unlock(Object key)
lock(Object,int)
method.
key
- The lock key for synchronization.public static void runParallel(Object key, ParallelRunnable parallelRunnable) throws ApfloatRuntimeException
lock(Object,int)
method with the same key
. The Runnables
for processing the strides are run using the ExecutorService retrieved from
ApfloatContext.getExecutorService()
.
key
- The lock key for synchronization.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 |