|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjsr166y.forkjoin.ForkJoinTask<java.lang.Void>
jsr166y.forkjoin.CyclicAction
public abstract class CyclicAction
A computation that is broken into a series of task executions, each separated by a TaskBarrier arrival. Concrete subclasses must define method compute, that performs the action occurring at each step of the barrier. Upon invocation of this task, the compute method is repeatedly invoked until the barrier isTerminated or until its execution throws an exception.
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 Summary | |
---|---|
CyclicAction(TaskBarrier barrier)
Constructs a new CyclicAction using the supplied barrier, registering for this barrier upon construction. |
Method Summary | |
---|---|
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. |
Methods inherited from class jsr166y.forkjoin.ForkJoinTask |
---|
cancel, fork, getException, isCancelled, isDone, isStolen, join, quietlyJoin, reinitialize |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CyclicAction(TaskBarrier barrier)
barrier
- the barrierMethod Detail |
---|
protected 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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |