15 |
|
* CountedCompleter are similar to those of other completion based |
16 |
|
* components (such as {@link java.nio.channels.CompletionHandler}) |
17 |
|
* except that multiple <em>pending</em> completions may be necessary |
18 |
< |
* to trigger the {@link #onCompletion} action, not just one. Unless |
19 |
< |
* initialized otherwise, the {@link #getPendingCount pending count} |
20 |
< |
* starts at zero, but may be (atomically) changed using methods |
21 |
< |
* {@link #setPendingCount}, {@link #addToPendingCount}, and {@link |
22 |
< |
* #compareAndSetPendingCount}. Upon invocation of {@link |
18 |
> |
* to trigger the completion action {@link #onCompletion}, not just one. |
19 |
> |
* Unless initialized otherwise, the {@linkplain #getPendingCount pending |
20 |
> |
* count} starts at zero, but may be (atomically) changed using |
21 |
> |
* methods {@link #setPendingCount}, {@link #addToPendingCount}, and |
22 |
> |
* {@link #compareAndSetPendingCount}. Upon invocation of {@link |
23 |
|
* #tryComplete}, if the pending action count is nonzero, it is |
24 |
|
* decremented; otherwise, the completion action is performed, and if |
25 |
|
* this completer itself has a completer, the process is continued |
183 |
|
* |
184 |
|
* <p><b>Searching.</b> A tree of CountedCompleters can search for a |
185 |
|
* value or property in different parts of a data structure, and |
186 |
< |
* report a result in an {@link java.util.concurrent.AtomicReference} |
187 |
< |
* as soon as one is found. The others can poll the result to avoid |
188 |
< |
* unnecessary work. (You could additionally {@link #cancel} other |
189 |
< |
* tasks, but it is usually simpler and more efficient to just let |
190 |
< |
* them notice that the result is set and if so skip further |
191 |
< |
* processing.) Illustrating again with an array using full |
186 |
> |
* report a result in an {@link |
187 |
> |
* java.util.concurrent.atomic.AtomicReference AtomicReference} as |
188 |
> |
* soon as one is found. The others can poll the result to avoid |
189 |
> |
* unnecessary work. (You could additionally {@linkplain #cancel |
190 |
> |
* cancel} other tasks, but it is usually simpler and more efficient |
191 |
> |
* to just let them notice that the result is set and if so skip |
192 |
> |
* further processing.) Illustrating again with an array using full |
193 |
|
* partitioning (again, in practice, leaf tasks will almost always |
194 |
|
* process more than one element): |
195 |
|
* |