71 |
|
* but doing do requires three further considerations: (1) Completion |
72 |
|
* of few if any <em>other</em> tasks should be dependent on a task |
73 |
|
* that blocks on external synchronization or IO. Event-style async |
74 |
< |
* tasks that are never joined often fall into this category. (2) To |
75 |
< |
* minimize resource impact, tasks should be small; ideally performing |
76 |
< |
* only the (possibly) blocking action. (3) Unless the {@link |
74 |
> |
* tasks that are never joined (for example, those subclassing {@link |
75 |
> |
* CountedCompleter}) often fall into this category. (2) To minimize |
76 |
> |
* resource impact, tasks should be small; ideally performing only the |
77 |
> |
* (possibly) blocking action. (3) Unless the {@link |
78 |
|
* ForkJoinPool.ManagedBlocker} API is used, or the number of possibly |
79 |
|
* blocked tasks is known to be less than the pool's {@link |
80 |
|
* ForkJoinPool#getParallelism} level, the pool cannot guarantee that |
140 |
|
* {@link Phaser}, {@link #helpQuiesce}, and {@link #complete}) that |
141 |
|
* may be of use in constructing custom subclasses for problems that |
142 |
|
* are not statically structured as DAGs. To support such usages a |
143 |
< |
* ForkJoinTask may be atomically <em>tagged</em> with a {@code |
144 |
< |
* short} value using {@link #setForkJoinTaskTag} or {@link |
143 |
> |
* ForkJoinTask may be atomically <em>tagged</em> with a {@code short} |
144 |
> |
* value using {@link #setForkJoinTaskTag} or {@link |
145 |
|
* #compareAndSetForkJoinTaskTag} and checked using {@link |
146 |
< |
* #getForkJoinTaskTag}. The ForkJoinTask implementation does not |
147 |
< |
* use these {@code protected} methods or tags for any purpose, but |
148 |
< |
* they may be of use in the construction of specialized subclasses. |
149 |
< |
* For example, parallel graph traversals can use the supplied methods |
150 |
< |
* to avoid revisiting nodes/tasks that have already been processed. |
151 |
< |
* Also, completion based designs can use them to record that subtasks |
152 |
< |
* have completed. (Method names for tagging are bulky in part to |
152 |
< |
* encourage definition of methods that reflect their usage patterns.) |
146 |
> |
* #getForkJoinTaskTag}. The ForkJoinTask implementation does not use |
147 |
> |
* these {@code protected} methods or tags for any purpose, but they |
148 |
> |
* may be of use in the construction of specialized subclasses. For |
149 |
> |
* example, parallel graph traversals can use the supplied methods to |
150 |
> |
* avoid revisiting nodes/tasks that have already been processed. |
151 |
> |
* (Method names for tagging are bulky in part to encourage definition |
152 |
> |
* of methods that reflect their usage patterns.) |
153 |
|
* |
154 |
|
* <p>Most base support methods are {@code final}, to prevent |
155 |
|
* overriding of implementations that are intrinsically tied to the |
412 |
|
} |
413 |
|
|
414 |
|
/** |
415 |
< |
* Records exception and sets exceptional completion. |
415 |
> |
* Records exception and sets status. |
416 |
|
* |
417 |
|
* @return status on exit |
418 |
|
*/ |
419 |
< |
private int setExceptionalCompletion(Throwable ex) { |
419 |
> |
final int recordExceptionalCompletion(Throwable ex) { |
420 |
|
int s; |
421 |
|
if ((s = status) >= 0) { |
422 |
|
int h = System.identityHashCode(this); |
439 |
|
} |
440 |
|
s = setCompletion(EXCEPTIONAL); |
441 |
|
} |
442 |
– |
ForkJoinTask<?> p = internalGetCompleter(); // propagate |
443 |
– |
if (p != null && p.status >= 0) |
444 |
– |
p.setExceptionalCompletion(ex); |
442 |
|
return s; |
443 |
|
} |
444 |
|
|
445 |
|
/** |
446 |
< |
* Exception propagation support for tasks with completers. |
446 |
> |
* Records exception and possibly propagates |
447 |
> |
* |
448 |
> |
* @return status on exit |
449 |
> |
*/ |
450 |
> |
private int setExceptionalCompletion(Throwable ex) { |
451 |
> |
int s = recordExceptionalCompletion(ex); |
452 |
> |
if ((s & DONE_MASK) == EXCEPTIONAL) |
453 |
> |
internalPropagateException(ex); |
454 |
> |
return s; |
455 |
> |
} |
456 |
> |
|
457 |
> |
/** |
458 |
> |
* Hook for exception propagation support for tasks with completers. |
459 |
|
*/ |
460 |
< |
ForkJoinTask<?> internalGetCompleter() { |
452 |
< |
return null; |
460 |
> |
void internalPropagateException(Throwable ex) { |
461 |
|
} |
462 |
|
|
463 |
|
/** |