109 |
|
return n; |
110 |
|
FibTask f1 = new FibTask(n - 1); |
111 |
|
f1.fork(); |
112 |
< |
return (new FibTask(n - 2)).compute() + f1.join(); |
112 |
> |
return new FibTask(n - 2).compute() + f1.join(); |
113 |
|
} |
114 |
|
} |
115 |
|
|
348 |
|
p.shutdown(); |
349 |
|
assertTrue(p.isShutdown()); |
350 |
|
try { |
351 |
< |
ForkJoinTask<Integer> f = p.submit(new FibTask(8)); |
351 |
> |
ForkJoinTask<Integer> unused = p.submit(new FibTask(8)); |
352 |
|
shouldThrow(); |
353 |
|
} catch (RejectedExecutionException success) {} |
354 |
|
} |
377 |
|
final CountDownLatch done = new CountDownLatch(1); |
378 |
|
SubFJP p = new SubFJP(); |
379 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
380 |
< |
ForkJoinTask a = p.submit(awaiter(done)); |
381 |
< |
ForkJoinTask b = p.submit(awaiter(done)); |
382 |
< |
ForkJoinTask c = p.submit(awaiter(done)); |
383 |
< |
ForkJoinTask r = p.pollSubmission(); |
380 |
> |
ForkJoinTask<?> a = p.submit(awaiter(done)); |
381 |
> |
ForkJoinTask<?> b = p.submit(awaiter(done)); |
382 |
> |
ForkJoinTask<?> c = p.submit(awaiter(done)); |
383 |
> |
ForkJoinTask<?> r = p.pollSubmission(); |
384 |
|
assertTrue(r == a || r == b || r == c); |
385 |
|
assertFalse(r.isDone()); |
386 |
|
done.countDown(); |
394 |
|
final CountDownLatch done = new CountDownLatch(1); |
395 |
|
SubFJP p = new SubFJP(); |
396 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
397 |
< |
ForkJoinTask a = p.submit(awaiter(done)); |
398 |
< |
ForkJoinTask b = p.submit(awaiter(done)); |
399 |
< |
ForkJoinTask c = p.submit(awaiter(done)); |
400 |
< |
ArrayList<ForkJoinTask> al = new ArrayList(); |
397 |
> |
ForkJoinTask<?> a = p.submit(awaiter(done)); |
398 |
> |
ForkJoinTask<?> b = p.submit(awaiter(done)); |
399 |
> |
ForkJoinTask<?> c = p.submit(awaiter(done)); |
400 |
> |
ArrayList<ForkJoinTask<?>> al = new ArrayList<>(); |
401 |
|
p.drainTasksTo(al); |
402 |
|
assertTrue(al.size() > 0); |
403 |
< |
for (ForkJoinTask r : al) { |
403 |
> |
for (ForkJoinTask<?> r : al) { |
404 |
|
assertTrue(r == a || r == b || r == c); |
405 |
|
assertFalse(r.isDone()); |
406 |
|
} |
472 |
|
* A submitted privileged action runs to completion |
473 |
|
*/ |
474 |
|
public void testSubmitPrivilegedAction() throws Exception { |
475 |
< |
final Callable callable = Executors.callable(new PrivilegedAction() { |
475 |
> |
final Callable<Object> callable = Executors.callable(new PrivilegedAction<Object>() { |
476 |
|
public Object run() { return TEST_STRING; }}); |
477 |
|
Runnable r = new CheckedRunnable() { |
478 |
|
public void realRun() throws Exception { |
479 |
|
ExecutorService e = new ForkJoinPool(1); |
480 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
481 |
< |
Future future = e.submit(callable); |
481 |
> |
Future<Object> future = e.submit(callable); |
482 |
|
assertSame(TEST_STRING, future.get()); |
483 |
|
} |
484 |
|
}}; |
490 |
|
* A submitted privileged exception action runs to completion |
491 |
|
*/ |
492 |
|
public void testSubmitPrivilegedExceptionAction() throws Exception { |
493 |
< |
final Callable callable = |
494 |
< |
Executors.callable(new PrivilegedExceptionAction() { |
493 |
> |
final Callable<Object> callable = |
494 |
> |
Executors.callable(new PrivilegedExceptionAction<Object>() { |
495 |
|
public Object run() { return TEST_STRING; }}); |
496 |
|
Runnable r = new CheckedRunnable() { |
497 |
|
public void realRun() throws Exception { |
498 |
|
ExecutorService e = new ForkJoinPool(1); |
499 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
500 |
< |
Future future = e.submit(callable); |
500 |
> |
Future<Object> future = e.submit(callable); |
501 |
|
assertSame(TEST_STRING, future.get()); |
502 |
|
} |
503 |
|
}}; |
509 |
|
* A submitted failed privileged exception action reports exception |
510 |
|
*/ |
511 |
|
public void testSubmitFailedPrivilegedExceptionAction() throws Exception { |
512 |
< |
final Callable callable = |
513 |
< |
Executors.callable(new PrivilegedExceptionAction() { |
512 |
> |
final Callable<Object> callable = |
513 |
> |
Executors.callable(new PrivilegedExceptionAction<Object>() { |
514 |
|
public Object run() { throw new IndexOutOfBoundsException(); }}); |
515 |
|
Runnable r = new CheckedRunnable() { |
516 |
|
public void realRun() throws Exception { |
517 |
|
ExecutorService e = new ForkJoinPool(1); |
518 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
519 |
< |
Future future = e.submit(callable); |
519 |
> |
Future<Object> future = e.submit(callable); |
520 |
|
try { |
521 |
|
future.get(); |
522 |
|
shouldThrow(); |
536 |
|
ExecutorService e = new ForkJoinPool(1); |
537 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
538 |
|
try { |
539 |
< |
Future<?> future = e.submit((Runnable) null); |
539 |
> |
Future<?> unused = e.submit((Runnable) null); |
540 |
|
shouldThrow(); |
541 |
|
} catch (NullPointerException success) {} |
542 |
|
} |
549 |
|
ExecutorService e = new ForkJoinPool(1); |
550 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
551 |
|
try { |
552 |
< |
Future<String> future = e.submit((Callable) null); |
552 |
> |
Future<String> unused = e.submit((Callable<String>) null); |
553 |
|
shouldThrow(); |
554 |
|
} catch (NullPointerException success) {} |
555 |
|
} |
561 |
|
public void testInterruptedSubmit() throws InterruptedException { |
562 |
|
final CountDownLatch submitted = new CountDownLatch(1); |
563 |
|
final CountDownLatch quittingTime = new CountDownLatch(1); |
564 |
< |
final Callable<Void> awaiter = new CheckedCallable<Void>() { |
564 |
> |
final Callable<Void> awaiter = new CheckedCallable<>() { |
565 |
|
public Void realCall() throws InterruptedException { |
566 |
|
assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS)); |
567 |
|
return null; |
589 |
|
ForkJoinPool p = new ForkJoinPool(1); |
590 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
591 |
|
try { |
592 |
< |
p.submit(new Callable() { |
592 |
> |
p.submit(new Callable<Object>() { |
593 |
|
public Object call() { throw new ArithmeticException(); }}) |
594 |
|
.get(); |
595 |
|
shouldThrow(); |