64 |
|
} |
65 |
|
} |
66 |
|
|
67 |
+ |
static class MyError extends Error {} |
68 |
+ |
|
69 |
|
// to test handlers |
70 |
|
static class FailingFJWSubclass extends ForkJoinWorkerThread { |
71 |
|
public FailingFJWSubclass(ForkJoinPool p) { super(p) ; } |
72 |
< |
protected void onStart() { super.onStart(); throw new Error(); } |
72 |
> |
protected void onStart() { super.onStart(); throw new MyError(); } |
73 |
|
} |
74 |
|
|
75 |
|
static class FailingThreadFactory |
258 |
|
*/ |
259 |
|
public void testSetUncaughtExceptionHandler() throws InterruptedException { |
260 |
|
final CountDownLatch uehInvoked = new CountDownLatch(1); |
261 |
< |
final Thread.UncaughtExceptionHandler eh = |
261 |
> |
final Thread.UncaughtExceptionHandler ueh = |
262 |
|
new Thread.UncaughtExceptionHandler() { |
263 |
|
public void uncaughtException(Thread t, Throwable e) { |
264 |
+ |
threadAssertTrue(e instanceof MyError); |
265 |
+ |
threadAssertTrue(t instanceof FailingFJWSubclass); |
266 |
|
uehInvoked.countDown(); |
267 |
|
}}; |
268 |
|
ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), |
269 |
< |
eh, false); |
270 |
< |
try { |
271 |
< |
assertSame(eh, p.getUncaughtExceptionHandler()); |
269 |
> |
ueh, false); |
270 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
271 |
> |
assertSame(ueh, p.getUncaughtExceptionHandler()); |
272 |
|
try { |
273 |
|
p.execute(new FibTask(8)); |
274 |
< |
assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
275 |
< |
} catch (RejectedExecutionException ok) { |
274 |
> |
await(uehInvoked); |
275 |
> |
} finally { |
276 |
> |
p.shutdownNow(); // failure might have prevented processing task |
277 |
|
} |
273 |
– |
} finally { |
274 |
– |
p.shutdownNow(); // failure might have prevented processing task |
275 |
– |
joinPool(p); |
278 |
|
} |
279 |
|
} |
280 |
|
|
550 |
|
public void testInterruptedSubmit() throws InterruptedException { |
551 |
|
final CountDownLatch submitted = new CountDownLatch(1); |
552 |
|
final CountDownLatch quittingTime = new CountDownLatch(1); |
551 |
– |
final ExecutorService p = new ForkJoinPool(1); |
553 |
|
final Callable<Void> awaiter = new CheckedCallable<Void>() { |
554 |
|
public Void realCall() throws InterruptedException { |
555 |
< |
assertTrue(quittingTime.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
555 |
> |
assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS)); |
556 |
|
return null; |
557 |
|
}}; |
558 |
< |
try { |
558 |
> |
final ExecutorService p = new ForkJoinPool(1); |
559 |
> |
try (PoolCleaner cleaner = cleaner(p, quittingTime)) { |
560 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
561 |
|
public void realRun() throws Exception { |
562 |
|
Future<Void> future = p.submit(awaiter); |
564 |
|
future.get(); |
565 |
|
}}); |
566 |
|
t.start(); |
567 |
< |
assertTrue(submitted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
567 |
> |
await(submitted); |
568 |
|
t.interrupt(); |
569 |
< |
t.join(); |
568 |
< |
} finally { |
569 |
< |
quittingTime.countDown(); |
570 |
< |
joinPool(p); |
569 |
> |
awaitTermination(t); |
570 |
|
} |
571 |
|
} |
572 |
|
|
912 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
913 |
|
l.add(new NPETask()); |
914 |
|
List<Future<String>> futures |
915 |
< |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
915 |
> |
= e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); |
916 |
|
assertEquals(1, futures.size()); |
917 |
|
try { |
918 |
|
futures.get(0).get(); |