--- jsr166/src/test/loops/LinkedAsyncAction.java 2012/10/21 06:14:12 1.5 +++ jsr166/src/test/loops/LinkedAsyncAction.java 2015/01/15 18:34:19 1.14 @@ -11,48 +11,48 @@ import java.util.concurrent.atomic.*; /** * AsyncActions that may be linked in parent-child relationships. * - *

Upon construction, an LinkedAsyncAction may register as a + *

Upon construction, a LinkedAsyncAction may register as a * subtask of a given parent task. In this case, completion of this * task will propagate to its parent. If the parent's pending subtask * completion count becomes zero, it too will complete. - * LinkedAsyncActions rarely use methods join or - * invoke but instead propagate completion to parents - * implicitly via complete. While typical, it is not necessary - * for each task to complete itself. For example, it is + * LinkedAsyncActions rarely use methods {@code join} or + * {@code invoke} but instead propagate completion to parents + * implicitly via {@code complete}. While typical, it is not necessary + * for each task to {@code complete} itself. For example, it is * possible to treat one subtask as a continuation of the current task * by not registering it on construction. In this case, a - * complete of the subtask will trigger complete of the + * {@code complete} of the subtask will trigger {@code complete} of the * parent without the parent explicitly doing so. * - *

In addition to supporting these different computation styles + *

In addition to supporting these different computation styles * compared to Recursive tasks, LinkedAsyncActions may have smaller * stack space footprints while executing, but may have greater * per-task overhead. * - *

Sample Usage. Here is a sketch of an LinkedAsyncAction + *

Sample Usage. Here is a sketch of a LinkedAsyncAction * that visits all of the nodes of a graph. The details of the graph's * Node and Edge classes are omitted, but we assume each node contains - * an AtomicBoolean mark that starts out false. To execute + * an {@code AtomicBoolean} mark that starts out false. To execute * this, you would create a GraphVisitor for the root node with null - * parent, and invoke in a ForkJoinPool. Upon return, all + * parent, and {@code invoke} in a ForkJoinPool. Upon return, all * reachable nodes will have been visited. * *

  * class GraphVisitor extends LinkedAsyncAction {
- *    final Node node;
- *    GraphVisitor(GraphVistor parent, Node node) {
- *      super(parent); this.node = node;
- *    }
- *    protected void compute() {
- *      if (node.mark.compareAndSet(false, true)) {
- *         for (Edge e : node.edges()) {
- *            Node dest = e.getDestination();
- *            if (!dest.mark.get())
- *               new GraphVisitor(this, dest).fork();
- *         }
- *         visit(node);
- *      }
- *      complete();
+ *   final Node node;
+ *   GraphVisitor(GraphVistor parent, Node node) {
+ *     super(parent); this.node = node;
+ *   }
+ *   protected void compute() {
+ *     if (node.mark.compareAndSet(false, true)) {
+ *       for (Edge e : node.edges()) {
+ *         Node dest = e.getDestination();
+ *         if (!dest.mark.get())
+ *           new GraphVisitor(this, dest).fork();
+ *       }
+ *       visit(node);
+ *     }
+ *     complete();
  *   }
  * }
  * 
@@ -69,7 +69,6 @@ public abstract class LinkedAsyncAction static final AtomicIntegerFieldUpdater controlStateUpdater = AtomicIntegerFieldUpdater.newUpdater(LinkedAsyncAction.class, "controlState"); - /** * Parent to notify on completion */ @@ -77,14 +76,14 @@ public abstract class LinkedAsyncAction /** * Creates a new action with no parent. (You can add a parent - * later (but before forking) via reinitialize). + * later (but before forking) via {@code reinitialize}). */ protected LinkedAsyncAction() { } /** * Creates a new action with the given parent. If the parent is - * non-null, this tasks registers with the parent, in which case, + * non-null, this task registers with the parent, in which case, * the parent task cannot complete until this task completes. * @param parent the parent task, or null if none */ @@ -97,7 +96,7 @@ public abstract class LinkedAsyncAction /** * Creates a new action with the given parent, optionally * registering with the parent. If the parent is non-null and - * register is true, this tasks registers with the + * {@code register} is true, this task registers with the * parent, in which case, the parent task cannot complete until * this task completes. * @param parent the parent task, or null if none @@ -114,7 +113,7 @@ public abstract class LinkedAsyncAction * Creates a new action with the given parent, optionally * registering with the parent, and setting the pending join count * to the given value. If the parent is non-null and - * register is true, this tasks registers with the + * {@code register} is true, this task registers with the * parent, in which case, the parent task cannot complete until * this task completes. Setting the pending join count requires * care -- it is correct only if child tasks do not themselves @@ -137,9 +136,9 @@ public abstract class LinkedAsyncAction protected final void setRawResult(Void mustBeNull) { } /** - * Overridable callback action triggered by complete. Upon + * Overridable callback action triggered by {@code complete}. Upon * invocation, all subtasks have completed. After return, this - * task isDone and is joinable by other tasks. The + * task {@code isDone} and is joinable by other tasks. The * default version of this method does nothing. But it may be * overridden in subclasses to perform some action when this task * is about to complete. @@ -149,15 +148,15 @@ public abstract class LinkedAsyncAction /** * Overridable callback action triggered by - * completeExceptionally. Upon invocation, this task has + * {@code completeExceptionally}. Upon invocation, this task has * aborted due to an exception (accessible via - * getException). If this method returns true, + * {@code getException}). If this method returns {@code true}, * the exception propagates to the current task's * parent. Otherwise, normal completion is propagated. The * default version of this method does nothing and returns - * true. + * {@code true}. * @return true if this task's exception should be propagated to - * this tasks parent. + * this task's parent */ protected boolean onException() { return true; @@ -175,12 +174,12 @@ public abstract class LinkedAsyncAction /** * Completes this task. If the pending subtask completion count is - * zero, invokes onCompletion, then causes this task to - * be joinable (isDone becomes true), and then - * recursively applies to this tasks's parent, if it exists. If an - * exception is encountered in any onCompletion + * zero, invokes {@code onCompletion}, then causes this task to + * be joinable ({@code isDone} becomes true), and then + * recursively applies to this task's parent, if it exists. If an + * exception is encountered in any {@code onCompletion} * invocation, that task and its ancestors - * completeExceptionally. + * {@code completeExceptionally}. */ public final void complete() { LinkedAsyncAction a = this; @@ -204,15 +203,15 @@ public abstract class LinkedAsyncAction /** * Completes this task abnormally. Unless this task already * cancelled or aborted, upon invocation, this method invokes - * onException, and then, depending on its return value, - * completees parent (if one exists) exceptionally or normally. To + * {@code onException}, and then, depending on its return value, + * completes parent (if one exists) exceptionally or normally. To * avoid unbounded exception loops, this method aborts if an - * exception is encountered in any onException + * exception is encountered in any {@code onException} * invocation. * @param ex the exception to throw when joining this task * @throws NullPointerException if ex is null * @throws Throwable if any invocation of - * onException does so. + * {@code onException} does so */ public final void completeExceptionally(Throwable ex) { LinkedAsyncAction a = this; @@ -231,7 +230,7 @@ public abstract class LinkedAsyncAction /** * Returns this task's parent, or null if none. - * @return this task's parent, or null if none. + * @return this task's parent, or null if none */ public final LinkedAsyncAction getParent() { return parent; @@ -239,7 +238,7 @@ public abstract class LinkedAsyncAction /** * Returns the number of subtasks that have not yet completed. - * @return the number of subtasks that have not yet completed. + * @return the number of subtasks that have not yet completed */ public final int getPendingSubtaskCount() { return getControlState(); @@ -340,5 +339,4 @@ public abstract class LinkedAsyncAction controlStateUpdater.decrementAndGet(this); } - }