/* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ */ import java.util.*; import java.util.concurrent.*; /** * A computation that is broken into a series of task executions, each * separated by a Phaser arrival. Concrete subclasses must * define method {@code compute}, that performs the action occurring * at each step of the barrier. Upon invocation of this task, the * {@code compute} method is repeatedly invoked until the barrier * {@code 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() { * Phaser b = new Phaser() { * protected boolean onAdvance(int cycle, int registeredParties) { * return registeredParties <= 0 || cycle >= 500; * } * } * int n = pool.getParallelismLevel(); * CyclicAction[] actions = new CyclicAction[n]; * for (int i = 0; i < n; ++i) { * action[i] = new CyclicAction(b) { * protected void compute() { * smoothImagePart(i); * } * } * } * invokeAll(actions); * } * } **/ public abstract class CyclicAction extends ForkJoinTask