7 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
|
import static java.util.concurrent.TimeUnit.SECONDS; |
9 |
|
|
10 |
+ |
import java.util.Arrays; |
11 |
+ |
import java.util.Collections; |
12 |
|
import java.util.HashSet; |
13 |
+ |
import java.util.List; |
14 |
|
import java.util.concurrent.CancellationException; |
15 |
|
import java.util.concurrent.ExecutionException; |
16 |
|
import java.util.concurrent.ForkJoinPool; |
256 |
|
super.completeExceptionally(ex); |
257 |
|
} |
258 |
|
|
259 |
+ |
public boolean cancel(boolean mayInterruptIfRunning) { |
260 |
+ |
if (super.cancel(mayInterruptIfRunning)) { |
261 |
+ |
completeExceptionally(new FJException()); |
262 |
+ |
return true; |
263 |
+ |
} |
264 |
+ |
return false; |
265 |
+ |
} |
266 |
+ |
|
267 |
|
public final void complete() { |
268 |
|
BinaryAsyncAction a = this; |
269 |
|
for (;;) { |
285 |
|
} |
286 |
|
|
287 |
|
public final void completeExceptionally(Throwable ex) { |
288 |
< |
BinaryAsyncAction a = this; |
278 |
< |
while (!a.isCompletedAbnormally()) { |
288 |
> |
for (BinaryAsyncAction a = this;;) { |
289 |
|
a.completeThisExceptionally(ex); |
290 |
|
BinaryAsyncAction s = a.sibling; |
291 |
< |
if (s != null) |
292 |
< |
s.cancel(false); |
293 |
< |
if (!a.onException() || (a = a.parent) == null) |
291 |
> |
if (s != null && !s.isDone()) |
292 |
> |
s.completeExceptionally(ex); |
293 |
> |
if ((a = a.parent) == null) |
294 |
|
break; |
295 |
|
} |
296 |
|
} |
881 |
|
protected void realCompute() { |
882 |
|
AsyncFib f = new AsyncFib(8); |
883 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
884 |
+ |
ForkJoinTask[] tasks = { f, g }; |
885 |
+ |
Collections.shuffle(Arrays.asList(tasks)); |
886 |
|
try { |
887 |
< |
invokeAll(f, g); |
887 |
> |
invokeAll(tasks); |
888 |
|
shouldThrow(); |
889 |
|
} catch (FJException success) { |
890 |
|
checkCompletedAbnormally(g, success); |
919 |
|
AsyncFib f = new AsyncFib(8); |
920 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
921 |
|
AsyncFib h = new AsyncFib(7); |
922 |
+ |
ForkJoinTask[] tasks = { f, g, h }; |
923 |
+ |
Collections.shuffle(Arrays.asList(tasks)); |
924 |
|
try { |
925 |
< |
invokeAll(f, g, h); |
925 |
> |
invokeAll(tasks); |
926 |
|
shouldThrow(); |
927 |
|
} catch (FJException success) { |
928 |
|
checkCompletedAbnormally(g, success); |
940 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
941 |
|
AsyncFib g = new AsyncFib(9); |
942 |
|
AsyncFib h = new AsyncFib(7); |
943 |
< |
HashSet set = new HashSet(); |
944 |
< |
set.add(f); |
945 |
< |
set.add(g); |
932 |
< |
set.add(h); |
943 |
> |
ForkJoinTask[] tasks = { f, g, h }; |
944 |
> |
List taskList = Arrays.asList(tasks); |
945 |
> |
Collections.shuffle(taskList); |
946 |
|
try { |
947 |
< |
invokeAll(set); |
947 |
> |
invokeAll(taskList); |
948 |
|
shouldThrow(); |
949 |
|
} catch (FJException success) { |
950 |
|
checkCompletedAbnormally(f, success); |
1551 |
|
protected void realCompute() { |
1552 |
|
AsyncFib f = new AsyncFib(8); |
1553 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1554 |
+ |
ForkJoinTask[] tasks = { f, g }; |
1555 |
+ |
Collections.shuffle(Arrays.asList(tasks)); |
1556 |
|
try { |
1557 |
< |
invokeAll(f, g); |
1557 |
> |
invokeAll(tasks); |
1558 |
|
shouldThrow(); |
1559 |
|
} catch (FJException success) { |
1560 |
|
checkCompletedAbnormally(g, success); |
1589 |
|
AsyncFib f = new AsyncFib(8); |
1590 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1591 |
|
AsyncFib h = new AsyncFib(7); |
1592 |
+ |
ForkJoinTask[] tasks = { f, g, h }; |
1593 |
+ |
Collections.shuffle(Arrays.asList(tasks)); |
1594 |
|
try { |
1595 |
< |
invokeAll(f, g, h); |
1595 |
> |
invokeAll(tasks); |
1596 |
|
shouldThrow(); |
1597 |
|
} catch (FJException success) { |
1598 |
|
checkCompletedAbnormally(g, success); |
1610 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1611 |
|
AsyncFib g = new AsyncFib(9); |
1612 |
|
AsyncFib h = new AsyncFib(7); |
1613 |
< |
HashSet set = new HashSet(); |
1614 |
< |
set.add(f); |
1615 |
< |
set.add(g); |
1599 |
< |
set.add(h); |
1613 |
> |
ForkJoinTask[] tasks = { f, g, h }; |
1614 |
> |
List taskList = Arrays.asList(tasks); |
1615 |
> |
Collections.shuffle(taskList); |
1616 |
|
try { |
1617 |
< |
invokeAll(set); |
1617 |
> |
invokeAll(taskList); |
1618 |
|
shouldThrow(); |
1619 |
|
} catch (FJException success) { |
1620 |
|
checkCompletedAbnormally(f, success); |