jsr166y.forkjoin
public abstract class CyclicAction extends ForkJoinTask<java.lang.Void>
Sample Usage. Here is a sketch of a set of CyclicActions that each perform 500 iterations of an imagined image smoothing operation. Note that the aggregate ImageSmoother task itself is not a CyclicTask.
class ImageSmoother extends RecursiveAction { protected void compute() { TaskBarrier b = new TaskBarrier() { protected boolean terminate(int cycle, int registeredParties) { return registeredParties <= 0 || cycle >= 500; } } int n = pool.getPoolSize(); CyclicAction[] actions = new CyclicAction[n]; for (int i = 0; i < n; ++i) { action[i] = new CyclicAction(b) { protected void compute() { smoothImagePart(i); } } } for (int i = 0; i < n; ++i) actions[i].fork(); for (int i = 0; i < n; ++i) actions[i].join(); } }
Constructor and Description |
---|
CyclicAction(TaskBarrier barrier)
Constructs a new CyclicAction using the supplied barrier,
registering for this barrier upon construction.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
compute()
The computation performed by this task on each cycle of the
barrier.
|
java.lang.Throwable |
exec()
Immediately commences execution of this task by the current
worker thread unless already cancelled, returning any exception
thrown by its compute method.
|
void |
finish()
Equivalent to finish(null).
|
void |
finish(java.lang.Void result)
Completes this task, and if not already aborted or cancelled,
returning the given result upon join and related
operations.
|
void |
finishExceptionally(java.lang.Throwable ex)
Completes this task abnormally, and if not already aborted or
cancelled, causes it to throw the given exception upon
join and related operations.
|
java.lang.Void |
forkJoin()
Equivalent in effect to the sequence fork(); join();
but may be more efficient.
|
TaskBarrier |
getBarrier()
Returns the barrier
|
int |
getCycle()
Returns the current cycle of the barrier
|
java.lang.Void |
rawResult()
Always returns null.
|
cancel, fork, getException, isCancelled, isDone, isStolen, join, quietlyJoin, reinitialize
public CyclicAction(TaskBarrier barrier)
barrier
- the barrierprotected abstract void compute()
public final TaskBarrier getBarrier()
public final int getCycle()
public final java.lang.Void rawResult()
rawResult
in class ForkJoinTask<java.lang.Void>
public final java.lang.Throwable exec()
ForkJoinTask
exec
in class ForkJoinTask<java.lang.Void>
public final java.lang.Void forkJoin()
ForkJoinTask
forkJoin
in class ForkJoinTask<java.lang.Void>
public final void finish()
public final void finish(java.lang.Void result)
ForkJoinTask
finish
in class ForkJoinTask<java.lang.Void>
result
- the result to returnpublic final void finishExceptionally(java.lang.Throwable ex)
ForkJoinTask
finishExceptionally
in class ForkJoinTask<java.lang.Void>
ex
- the exception to throw. While not necessarily
statically enforced, this must be a RuntimeException or Error.