ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/LinkedAsyncAction.java
(Generate patch)

Comparing jsr166/src/test/loops/LinkedAsyncAction.java (file contents):
Revision 1.6 by jsr166, Sun Nov 18 18:03:11 2012 UTC vs.
Revision 1.9 by jsr166, Mon Nov 26 05:59:05 2012 UTC

# Line 11 | Line 11 | import java.util.concurrent.atomic.*;
11   /**
12   * AsyncActions that may be linked in parent-child relationships.
13   *
14 < * <p>Upon construction, an LinkedAsyncAction may register as a
14 > * <p>Upon construction, a LinkedAsyncAction may register as a
15   * subtask of a given parent task. In this case, completion of this
16   * task will propagate to its parent. If the parent's pending subtask
17   * completion count becomes zero, it too will complete.
# Line 29 | Line 29 | import java.util.concurrent.atomic.*;
29   * stack space footprints while executing, but may have greater
30   * per-task overhead.
31   *
32 < * <p><b>Sample Usage.</b> Here is a sketch of an LinkedAsyncAction
32 > * <p><b>Sample Usage.</b> Here is a sketch of a LinkedAsyncAction
33   * that visits all of the nodes of a graph. The details of the graph's
34   * Node and Edge classes are omitted, but we assume each node contains
35   * an <tt>AtomicBoolean</tt> mark that starts out false. To execute
# Line 39 | Line 39 | import java.util.concurrent.atomic.*;
39   *
40   * <pre>
41   * class GraphVisitor extends LinkedAsyncAction {
42 < *    final Node node;
43 < *    GraphVisitor(GraphVistor parent, Node node) {
44 < *      super(parent); this.node = node;
45 < *    }
46 < *    protected void compute() {
47 < *      if (node.mark.compareAndSet(false, true)) {
48 < *         for (Edge e : node.edges()) {
49 < *            Node dest = e.getDestination();
50 < *            if (!dest.mark.get())
51 < *               new GraphVisitor(this, dest).fork();
52 < *         }
53 < *         visit(node);
54 < *      }
55 < *      complete();
42 > *   final Node node;
43 > *   GraphVisitor(GraphVistor parent, Node node) {
44 > *     super(parent); this.node = node;
45 > *   }
46 > *   protected void compute() {
47 > *     if (node.mark.compareAndSet(false, true)) {
48 > *       for (Edge e : node.edges()) {
49 > *         Node dest = e.getDestination();
50 > *         if (!dest.mark.get())
51 > *           new GraphVisitor(this, dest).fork();
52 > *       }
53 > *       visit(node);
54 > *     }
55 > *     complete();
56   *   }
57   * }
58   * </pre>
# Line 84 | Line 84 | public abstract class LinkedAsyncAction
84  
85      /**
86       * Creates a new action with the given parent. If the parent is
87 <     * non-null, this tasks registers with the parent, in which case,
87 >     * non-null, this task registers with the parent, in which case,
88       * the parent task cannot complete until this task completes.
89       * @param parent the parent task, or null if none
90       */
# Line 97 | Line 97 | public abstract class LinkedAsyncAction
97      /**
98       * Creates a new action with the given parent, optionally
99       * registering with the parent. If the parent is non-null and
100 <     * <tt>register</tt> is true, this tasks registers with the
100 >     * <tt>register</tt> is true, this task registers with the
101       * parent, in which case, the parent task cannot complete until
102       * this task completes.
103       * @param parent the parent task, or null if none
# Line 114 | Line 114 | public abstract class LinkedAsyncAction
114       * Creates a new action with the given parent, optionally
115       * registering with the parent, and setting the pending join count
116       * to the given value. If the parent is non-null and
117 <     * <tt>register</tt> is true, this tasks registers with the
117 >     * <tt>register</tt> is true, this task registers with the
118       * parent, in which case, the parent task cannot complete until
119       * this task completes. Setting the pending join count requires
120       * care -- it is correct only if child tasks do not themselves
# Line 157 | Line 157 | public abstract class LinkedAsyncAction
157       * default version of this method does nothing and returns
158       * <tt>true</tt>.
159       * @return true if this task's exception should be propagated to
160 <     * this tasks parent.
160 >     * this task's parent.
161       */
162      protected boolean onException() {
163          return true;
# Line 177 | Line 177 | public abstract class LinkedAsyncAction
177       * Completes this task. If the pending subtask completion count is
178       * zero, invokes <tt>onCompletion</tt>, then causes this task to
179       * be joinable (<tt>isDone</tt> becomes true), and then
180 <     * recursively applies to this tasks's parent, if it exists. If an
180 >     * recursively applies to this task's parent, if it exists. If an
181       * exception is encountered in any <tt>onCompletion</tt>
182       * invocation, that task and its ancestors
183       * <tt>completeExceptionally</tt>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines