19 |
|
|
20 |
|
static final ForkJoinPool mainPool = new ForkJoinPool(); |
21 |
|
static final ForkJoinPool singletonPool = new ForkJoinPool(1); |
22 |
< |
static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1); |
23 |
< |
static { |
24 |
< |
asyncSingletonPool.setAsyncMode(true); |
25 |
< |
} |
22 |
> |
static final ForkJoinPool asyncSingletonPool = |
23 |
> |
new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
24 |
> |
null, true); |
25 |
|
|
26 |
|
static final class FJException extends RuntimeException { |
27 |
|
FJException() { super(); } |
165 |
|
} |
166 |
|
|
167 |
|
/** |
169 |
– |
* helpJoin of a forked task returns when task completes |
170 |
– |
*/ |
171 |
– |
public void testForkHelpJoin() { |
172 |
– |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
173 |
– |
public Integer compute() { |
174 |
– |
FibTask f = new FibTask(8); |
175 |
– |
f.fork(); |
176 |
– |
Integer r = f.helpJoin(); |
177 |
– |
threadAssertTrue(r == 21); |
178 |
– |
threadAssertTrue(f.isDone()); |
179 |
– |
return r; |
180 |
– |
} |
181 |
– |
}; |
182 |
– |
assertTrue(mainPool.invoke(a) == 21); |
183 |
– |
} |
184 |
– |
|
185 |
– |
/** |
168 |
|
* quietlyJoin of a forked task returns when task completes |
169 |
|
*/ |
170 |
|
public void testForkQuietlyJoin() { |
184 |
|
|
185 |
|
|
186 |
|
/** |
205 |
– |
* quietlyHelpJoin of a forked task returns when task completes |
206 |
– |
*/ |
207 |
– |
public void testForkQuietlyHelpJoin() { |
208 |
– |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
209 |
– |
public Integer compute() { |
210 |
– |
FibTask f = new FibTask(8); |
211 |
– |
f.fork(); |
212 |
– |
f.quietlyHelpJoin(); |
213 |
– |
Integer r = f.getRawResult(); |
214 |
– |
threadAssertTrue(r == 21); |
215 |
– |
threadAssertTrue(f.isDone()); |
216 |
– |
return r; |
217 |
– |
} |
218 |
– |
}; |
219 |
– |
assertTrue(mainPool.invoke(a) == 21); |
220 |
– |
} |
221 |
– |
|
222 |
– |
|
223 |
– |
/** |
187 |
|
* helpQuiesce returns when tasks are complete. |
188 |
|
* getQueuedTaskCount returns 0 when quiescent |
189 |
|
*/ |
303 |
|
} |
304 |
|
|
305 |
|
/** |
343 |
– |
* join of a forked task throws exception when task completes abnormally |
344 |
– |
*/ |
345 |
– |
public void testAbnormalForkHelpJoin() { |
346 |
– |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
347 |
– |
public Integer compute() { |
348 |
– |
try { |
349 |
– |
FailingFibTask f = new FailingFibTask(8); |
350 |
– |
f.fork(); |
351 |
– |
Integer r = f.helpJoin(); |
352 |
– |
shouldThrow(); |
353 |
– |
return r; |
354 |
– |
} catch (FJException success) { |
355 |
– |
} |
356 |
– |
return NoResult; |
357 |
– |
} |
358 |
– |
}; |
359 |
– |
mainPool.invoke(a); |
360 |
– |
} |
361 |
– |
|
362 |
– |
/** |
363 |
– |
* quietlyHelpJoin of a forked task returns when task completes abnormally. |
364 |
– |
* getException of failed task returns its exception. |
365 |
– |
* isCompletedAbnormally of a failed task returns true. |
366 |
– |
* isCancelled of a failed uncancelled task returns false |
367 |
– |
*/ |
368 |
– |
public void testAbnormalForkQuietlyHelpJoin() { |
369 |
– |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
370 |
– |
public Integer compute() { |
371 |
– |
FailingFibTask f = new FailingFibTask(8); |
372 |
– |
f.fork(); |
373 |
– |
f.quietlyHelpJoin(); |
374 |
– |
threadAssertTrue(f.isDone()); |
375 |
– |
threadAssertTrue(f.isCompletedAbnormally()); |
376 |
– |
threadAssertFalse(f.isCancelled()); |
377 |
– |
threadAssertTrue(f.getException() instanceof FJException); |
378 |
– |
return NoResult; |
379 |
– |
} |
380 |
– |
}; |
381 |
– |
mainPool.invoke(a); |
382 |
– |
} |
383 |
– |
|
384 |
– |
/** |
306 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
307 |
|
*/ |
308 |
|
public void testAbnormalForkQuietlyJoin() { |
404 |
|
return NoResult; |
405 |
|
} |
406 |
|
}; |
486 |
– |
mainPool.invoke(a); |
487 |
– |
} |
488 |
– |
|
489 |
– |
/** |
490 |
– |
* join of a forked task throws exception when task cancelled |
491 |
– |
*/ |
492 |
– |
public void testCancelledForkHelpJoin() { |
493 |
– |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
494 |
– |
public Integer compute() { |
495 |
– |
try { |
496 |
– |
FibTask f = new FibTask(8); |
497 |
– |
f.cancel(true); |
498 |
– |
f.fork(); |
499 |
– |
Integer r = f.helpJoin(); |
500 |
– |
shouldThrow(); |
501 |
– |
return r; |
502 |
– |
} catch (CancellationException success) { |
503 |
– |
} |
504 |
– |
return NoResult; |
505 |
– |
} |
506 |
– |
}; |
507 |
– |
mainPool.invoke(a); |
508 |
– |
} |
509 |
– |
|
510 |
– |
/** |
511 |
– |
* quietlyHelpJoin of a forked task returns when task cancelled. |
512 |
– |
* getException of cancelled task returns its exception |
513 |
– |
* isCompletedAbnormally of a cancelled task returns true. |
514 |
– |
* isCancelled of a cancelled task returns true |
515 |
– |
*/ |
516 |
– |
public void testCancelledForkQuietlyHelpJoin() { |
517 |
– |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
518 |
– |
public Integer compute() { |
519 |
– |
FibTask f = new FibTask(8); |
520 |
– |
f.cancel(true); |
521 |
– |
f.fork(); |
522 |
– |
f.quietlyHelpJoin(); |
523 |
– |
threadAssertTrue(f.isDone()); |
524 |
– |
threadAssertTrue(f.isCompletedAbnormally()); |
525 |
– |
threadAssertTrue(f.isCancelled()); |
526 |
– |
threadAssertTrue(f.getException() instanceof CancellationException); |
527 |
– |
return NoResult; |
528 |
– |
} |
529 |
– |
}; |
407 |
|
mainPool.invoke(a); |
408 |
|
} |
409 |
|
|