256 |
|
*/ |
257 |
|
public void testSetUncaughtExceptionHandler() throws InterruptedException { |
258 |
|
final CountDownLatch uehInvoked = new CountDownLatch(1); |
259 |
< |
final Thread.UncaughtExceptionHandler eh = |
259 |
> |
final Thread.UncaughtExceptionHandler ueh = |
260 |
|
new Thread.UncaughtExceptionHandler() { |
261 |
|
public void uncaughtException(Thread t, Throwable e) { |
262 |
|
uehInvoked.countDown(); |
263 |
|
}}; |
264 |
|
ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), |
265 |
< |
eh, false); |
266 |
< |
try { |
267 |
< |
assertSame(eh, p.getUncaughtExceptionHandler()); |
265 |
> |
ueh, false); |
266 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
267 |
> |
assertSame(ueh, p.getUncaughtExceptionHandler()); |
268 |
|
try { |
269 |
< |
p.execute(new FibTask(8)); |
270 |
< |
assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
271 |
< |
} catch (RejectedExecutionException ok) { |
269 |
> |
try { |
270 |
> |
p.execute(new FibTask(8)); |
271 |
> |
await(uehInvoked); |
272 |
> |
} catch (RejectedExecutionException ok) {} |
273 |
> |
} finally { |
274 |
> |
p.shutdownNow(); // failure might have prevented processing task |
275 |
|
} |
273 |
– |
} finally { |
274 |
– |
p.shutdownNow(); // failure might have prevented processing task |
275 |
– |
joinPool(p); |
276 |
|
} |
277 |
|
} |
278 |
|
|