Exemplo n.º 1
0
 /**
  * setUncaughtExceptionHandler changes handler for uncaught exceptions.
  *
  * <p>Additionally tests: Overriding ForkJoinWorkerThread.onStart performs its defined action
  */
 public void testSetUncaughtExceptionHandler() throws InterruptedException {
   final CountDownLatch uehInvoked = new CountDownLatch(1);
   final Thread.UncaughtExceptionHandler ueh =
       new Thread.UncaughtExceptionHandler() {
         public void uncaughtException(Thread t, Throwable e) {
           threadAssertTrue(e instanceof MyError);
           threadAssertTrue(t instanceof FailingFJWSubclass);
           uehInvoked.countDown();
         }
       };
   ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), ueh, false);
   try (PoolCleaner cleaner = cleaner(p)) {
     assertSame(ueh, p.getUncaughtExceptionHandler());
     try {
       p.execute(new FibTask(8));
       await(uehInvoked);
     } finally {
       p.shutdownNow(); // failure might have prevented processing task
     }
   }
 }