ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ExecutorCompletionService.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ExecutorCompletionService.java (file contents):
Revision 1.5 by dl, Wed Dec 17 17:00:24 2003 UTC vs.
Revision 1.6 by dl, Fri Dec 19 14:42:25 2003 UTC

# Line 9 | Line 9 | package java.util.concurrent;
9  
10   /**
11   * A {@link CompletionService} that uses a supplied {@link Executor}
12 < * to execute tasks. An <tt>ExecutorCompletionService</tt> can be
13 < * useful as an add-on to solve task coordination problems.
12 > * to execute tasks.
13   *
14   * <p>
15   *
16   * <b>Usage Examples.</b>
17 < * Suppose you have a set of solvers for a certain problem,
17 > * Suppose you have a set of solvers for a certain problem (each returning
18 > * a value of some type <tt>Result</tt>),
19   * and would like to run them concurrently, using the results of each of them
20   * that return a non-null value. You could write this as:
21   *
22   * <pre>
23 < *    void solve(Executor e, Collection&lt;Callable&lt;Result&gt;&gt; solvers)
24 < *        throws InterruptedException, ExecutionException {
25 < *        ExecutorCompletionService&lt;Result&gt; ecs = new
26 < *            ExecutorCompletionService&lt;Result&gt;(e);
23 > *    void solve(Executor e, Collection&lt;Callable&lt;Result&gt;&gt; solvers)
24 > *      throws InterruptedException, ExecutionException {
25 > *        CompletionService&lt;Result&gt; ecs = new ExecutorCompletionService&lt;Result&gt;(e);
26   *        for (Callable&lt;Result&gt; s : solvers)
27   *            ecs.submit(s);
28   *        int n = solvers.size();
# Line 36 | Line 35 | package java.util.concurrent;
35   * </pre>
36   *
37   * Suppose instead that you would like to use the first non-null result
38 < * of a set of tasks, ignoring any of those that encounter exceptions
39 < * and cancelling all of the other tasks when the first one is ready:
38 > * of the set of tasks, ignoring any of those that encounter exceptions,
39 > * and cancelling all other tasks when the first one is ready:
40   *
41   * <pre>
42   *    void solve(Executor e, Collection&lt;Callable&lt;Result&gt;&gt; solvers)
43 < *        throws InterruptedException {
44 < *        ExecutorCompletionService&lt;Result&gt; ecs =
46 < *            new ExecutorCompletionService&lt;Result&gt;(e);
43 > *      throws InterruptedException {
44 > *        CompletionService&lt;Result&gt; ecs = new ExecutorCompletionService&lt;Result&gt;(e);
45   *        int n = solvers.size();
46 < *        ArrayList&lt;Future&lt;Result&gt;&gt; futures =
49 < *            new ArrayList&lt;Future&lt;Result&gt;&gt;(n);
46 > *        List&lt;Future&lt;Result&gt;&gt; futures = new ArrayList&lt;Future&lt;Result&gt;&gt;(n);
47   *        Result result = null;
48   *        try {
49   *            for (Callable&lt;Result&gt; s : solvers)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines