416 |
|
int r = f.get(); |
417 |
|
assertTrue(r == 832040); |
418 |
|
} finally { |
419 |
< |
joinPool(p); |
419 |
> |
p.shutdownNow(); // don't wait out shutdown |
420 |
|
} |
421 |
|
} |
422 |
|
|
636 |
|
void realRun() throws Throwable { |
637 |
|
p.submit(new CheckedCallable<Object>() { |
638 |
|
public Object realCall() throws Throwable { |
639 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
639 |
> |
try { |
640 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
641 |
> |
} catch (InterruptedException ok) { |
642 |
> |
} |
643 |
|
return null; |
644 |
|
}}).get(); |
645 |
|
}}); |
647 |
|
t.start(); |
648 |
|
Thread.sleep(SHORT_DELAY_MS); |
649 |
|
t.interrupt(); |
650 |
+ |
t.join(); |
651 |
+ |
p.shutdownNow(); |
652 |
|
joinPool(p); |
653 |
|
} |
654 |
|
|
658 |
|
*/ |
659 |
|
public void testSubmitEE() throws Throwable { |
660 |
|
ForkJoinPool p = new ForkJoinPool(1); |
656 |
– |
|
661 |
|
try { |
662 |
< |
Callable c = new Callable() { |
663 |
< |
public Object call() { |
664 |
< |
int i = 5/0; |
665 |
< |
return Boolean.TRUE; |
666 |
< |
} |
663 |
< |
}; |
664 |
< |
|
665 |
< |
for (int i = 0; i < 5; i++) { |
666 |
< |
p.submit(c).get(); |
667 |
< |
} |
662 |
> |
p.submit(new Callable() { |
663 |
> |
public Object call() { |
664 |
> |
int i = 5/0; |
665 |
> |
return Boolean.TRUE; |
666 |
> |
}}).get(); |
667 |
|
shouldThrow(); |
668 |
|
} catch (ExecutionException success) { |
669 |
|
} |
699 |
|
} |
700 |
|
|
701 |
|
/** |
702 |
< |
* invokeAny(c) throws NullPointerException if c has null elements |
702 |
> |
* invokeAny(c) throws NullPointerException if c has a single null element |
703 |
|
*/ |
704 |
|
public void testInvokeAny3() throws Throwable { |
705 |
|
ExecutorService e = new ForkJoinPool(1); |
706 |
|
try { |
707 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
709 |
– |
l.add(new StringTask()); |
708 |
|
l.add(null); |
709 |
|
e.invokeAny(l); |
710 |
|
shouldThrow(); |
715 |
|
} |
716 |
|
|
717 |
|
/** |
718 |
< |
* invokeAny(c) throws ExecutionException if no task in c completes |
718 |
> |
* invokeAny(c) throws NullPointerException if c has null elements |
719 |
|
*/ |
720 |
|
public void testInvokeAny4() throws Throwable { |
721 |
|
ExecutorService e = new ForkJoinPool(1); |
722 |
|
try { |
723 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
724 |
+ |
l.add(new Callable<String>() { |
725 |
+ |
public String call() { |
726 |
+ |
// The delay gives the pool a chance to notice |
727 |
+ |
// the null element. |
728 |
+ |
sleepTillInterrupted(SMALL_DELAY_MS); |
729 |
+ |
return "foo"; |
730 |
+ |
}}); |
731 |
+ |
l.add(null); |
732 |
+ |
e.invokeAny(l); |
733 |
+ |
shouldThrow(); |
734 |
+ |
} catch (NullPointerException success) { |
735 |
+ |
} finally { |
736 |
+ |
joinPool(e); |
737 |
+ |
} |
738 |
+ |
} |
739 |
+ |
|
740 |
+ |
/** |
741 |
+ |
* invokeAny(c) throws ExecutionException if no task in c completes |
742 |
+ |
*/ |
743 |
+ |
public void testInvokeAny5() throws Throwable { |
744 |
+ |
ExecutorService e = new ForkJoinPool(1); |
745 |
+ |
try { |
746 |
+ |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
747 |
|
l.add(new NPETask()); |
748 |
|
e.invokeAny(l); |
749 |
|
shouldThrow(); |
756 |
|
/** |
757 |
|
* invokeAny(c) returns result of some task in c if at least one completes |
758 |
|
*/ |
759 |
< |
public void testInvokeAny5() throws Throwable { |
759 |
> |
public void testInvokeAny6() throws Throwable { |
760 |
|
ExecutorService e = new ForkJoinPool(1); |
761 |
|
try { |
762 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |