jdk/test/java/util/concurrent/tck/ForkJoinPoolTest.java
changeset 41131 87edc8451f8a
parent 35394 282c3cb6a0c1
child 43522 f9c6f543c4db
equal deleted inserted replaced
41130:2004bf22423f 41131:87edc8451f8a
    49 import java.util.concurrent.ForkJoinWorkerThread;
    49 import java.util.concurrent.ForkJoinWorkerThread;
    50 import java.util.concurrent.Future;
    50 import java.util.concurrent.Future;
    51 import java.util.concurrent.RecursiveTask;
    51 import java.util.concurrent.RecursiveTask;
    52 import java.util.concurrent.RejectedExecutionException;
    52 import java.util.concurrent.RejectedExecutionException;
    53 import java.util.concurrent.atomic.AtomicBoolean;
    53 import java.util.concurrent.atomic.AtomicBoolean;
       
    54 import java.util.concurrent.atomic.AtomicInteger;
    54 import java.util.concurrent.locks.ReentrantLock;
    55 import java.util.concurrent.locks.ReentrantLock;
    55 
    56 
    56 import junit.framework.AssertionFailedError;
    57 import junit.framework.AssertionFailedError;
    57 import junit.framework.Test;
    58 import junit.framework.Test;
    58 import junit.framework.TestSuite;
    59 import junit.framework.TestSuite;
    82      * methods, but they are covered here and in task tests.
    83      * methods, but they are covered here and in task tests.
    83      */
    84      */
    84 
    85 
    85     // Some classes to test extension and factory methods
    86     // Some classes to test extension and factory methods
    86 
    87 
    87     static class MyHandler implements Thread.UncaughtExceptionHandler {
       
    88         volatile int catches = 0;
       
    89         public void uncaughtException(Thread t, Throwable e) {
       
    90             ++catches;
       
    91         }
       
    92     }
       
    93 
       
    94     static class MyError extends Error {}
    88     static class MyError extends Error {}
    95 
    89 
    96     // to test handlers
    90     // to test handlers
    97     static class FailingFJWSubclass extends ForkJoinWorkerThread {
    91     static class FailingFJWSubclass extends ForkJoinWorkerThread {
    98         public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
    92         public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
    99         protected void onStart() { super.onStart(); throw new MyError(); }
    93         protected void onStart() { super.onStart(); throw new MyError(); }
   100     }
    94     }
   101 
    95 
   102     static class FailingThreadFactory
    96     static class FailingThreadFactory
   103             implements ForkJoinPool.ForkJoinWorkerThreadFactory {
    97             implements ForkJoinPool.ForkJoinWorkerThreadFactory {
   104         volatile int calls = 0;
    98         final AtomicInteger calls = new AtomicInteger(0);
   105         public ForkJoinWorkerThread newThread(ForkJoinPool p) {
    99         public ForkJoinWorkerThread newThread(ForkJoinPool p) {
   106             if (++calls > 1) return null;
   100             if (calls.incrementAndGet() > 1) return null;
   107             return new FailingFJWSubclass(p);
   101             return new FailingFJWSubclass(p);
   108         }
   102         }
   109     }
   103     }
   110 
   104 
   111     static class SubFJP extends ForkJoinPool { // to expose protected
   105     static class SubFJP extends ForkJoinPool { // to expose protected