126 |
|
* op.apply(array[lo]); |
127 |
|
* tryComplete(); |
128 |
|
* } |
129 |
< |
* } }</pre> |
129 |
> |
* }}</pre> |
130 |
|
* |
131 |
|
* This design can be improved by noticing that in the recursive case, |
132 |
|
* the task has nothing to do after forking its right task, so can |
133 |
|
* directly invoke its left task before returning. (This is an analog |
134 |
|
* of tail recursion removal.) Also, because the task returns upon |
135 |
|
* executing its left task (rather than falling through to invoke |
136 |
< |
* tryComplete) the pending count is set to one: |
136 |
> |
* {@code tryComplete}) the pending count is set to one: |
137 |
|
* |
138 |
|
* <pre> {@code |
139 |
|
* class ForEach<E> ... |
277 |
|
* } |
278 |
|
* public void onCompletion(CountedCompleter<?> caller) { |
279 |
|
* if (caller != this) { |
280 |
< |
* MapReducer<E> child = (MapReducer<E>)caller; |
281 |
< |
* MapReducer<E> sib = child.sibling; |
282 |
< |
* if (sib == null || sib.result == null) |
283 |
< |
* result = child.result; |
284 |
< |
* else |
285 |
< |
* result = reducer.apply(child.result, sib.result); |
280 |
> |
* MapReducer<E> child = (MapReducer<E>)caller; |
281 |
> |
* MapReducer<E> sib = child.sibling; |
282 |
> |
* if (sib == null || sib.result == null) |
283 |
> |
* result = child.result; |
284 |
> |
* else |
285 |
> |
* result = reducer.apply(child.result, sib.result); |
286 |
|
* } |
287 |
|
* } |
288 |
|
* public E getRawResult() { return result; } |
291 |
|
* return new MapReducer<E>(null, array, mapper, reducer, |
292 |
|
* 0, array.length).invoke(); |
293 |
|
* } |
294 |
< |
* } }</pre> |
294 |
> |
* }}</pre> |
295 |
|
* |
296 |
|
* Here, method {@code onCompletion} takes a form common to many |
297 |
|
* completion designs that combine results. This callback-style method |
661 |
|
} |
662 |
|
|
663 |
|
/** |
664 |
< |
* Support for FJT exception propagation |
664 |
> |
* Supports ForkJoinTask exception propagation. |
665 |
|
*/ |
666 |
|
void internalPropagateException(Throwable ex) { |
667 |
|
CountedCompleter<?> a = this, s = a; |
671 |
|
} |
672 |
|
|
673 |
|
/** |
674 |
< |
* Implements execution conventions for CountedCompleters |
674 |
> |
* Implements execution conventions for CountedCompleters. |
675 |
|
*/ |
676 |
|
protected final boolean exec() { |
677 |
|
compute(); |