jdk/test/java/util/concurrent/BlockingQueue/ProducerConsumerLoops.java
changeset 4110 ac033ba6ede4
parent 3708 f838f712922e
child 4347 ab0a9f495844
equal deleted inserted replaced
4109:b997a0a1005d 4110:ac033ba6ede4
    85         pool.shutdown();
    85         pool.shutdown();
    86         if (! pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS))
    86         if (! pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS))
    87             throw new Error();
    87             throw new Error();
    88    }
    88    }
    89 
    89 
       
    90     static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
       
    91         LTQasSQ() { super(); }
       
    92         public void put(T x) {
       
    93             try { super.transfer(x); }
       
    94             catch (InterruptedException ex) { throw new Error(); }
       
    95         }
       
    96         private final static long serialVersionUID = 42;
       
    97     }
       
    98 
       
    99     static final class HalfSyncLTQ<T> extends LinkedTransferQueue<T> {
       
   100         HalfSyncLTQ() { super(); }
       
   101         public void put(T x) {
       
   102             if (ThreadLocalRandom.current().nextBoolean())
       
   103                 super.put(x);
       
   104             else {
       
   105                 try { super.transfer(x); }
       
   106                 catch (InterruptedException ex) { throw new Error(); }
       
   107             }
       
   108         }
       
   109         private final static long serialVersionUID = 42;
       
   110     }
       
   111 
    90     static void oneTest(int pairs, int iters) throws Exception {
   112     static void oneTest(int pairs, int iters) throws Exception {
    91         oneRun(new ArrayBlockingQueue<Integer>(CAPACITY), pairs, iters);
   113         oneRun(new ArrayBlockingQueue<Integer>(CAPACITY), pairs, iters);
    92         oneRun(new LinkedBlockingQueue<Integer>(CAPACITY), pairs, iters);
   114         oneRun(new LinkedBlockingQueue<Integer>(CAPACITY), pairs, iters);
    93         oneRun(new LinkedBlockingDeque<Integer>(CAPACITY), pairs, iters);
   115         oneRun(new LinkedBlockingDeque<Integer>(CAPACITY), pairs, iters);
    94 //         oneRun(new LinkedTransferQueue<Integer>(), pairs, iters);
   116         oneRun(new LinkedTransferQueue<Integer>(), pairs, iters);
       
   117         oneRun(new LTQasSQ<Integer>(), pairs, iters);
       
   118         oneRun(new HalfSyncLTQ<Integer>(), pairs, iters);
    95         oneRun(new PriorityBlockingQueue<Integer>(), pairs, iters);
   119         oneRun(new PriorityBlockingQueue<Integer>(), pairs, iters);
    96         oneRun(new SynchronousQueue<Integer>(), pairs, iters);
   120         oneRun(new SynchronousQueue<Integer>(), pairs, iters);
    97 
   121 
    98         if (print)
   122         if (print)
    99             System.out.println("fair implementations:");
   123             System.out.println("fair implementations:");