Print this page


Split Close
Expand all
Collapse all
          --- old/test/java/util/concurrent/BlockingQueue/SingleProducerMultipleConsumerLoops.java
          +++ new/test/java/util/concurrent/BlockingQueue/SingleProducerMultipleConsumerLoops.java
↓ open down ↓ 26 lines elided ↑ open up ↑
  27   27   * file:
  28   28   *
  29   29   * Written by Doug Lea with assistance from members of JCP JSR-166
  30   30   * Expert Group and released to the public domain, as explained at
  31   31   * http://creativecommons.org/licenses/publicdomain
  32   32   */
  33   33  
  34   34  /*
  35   35   * @test
  36   36   * @bug 4486658
  37      - * @compile SingleProducerMultipleConsumerLoops.java
       37 + * @compile -source 1.5 SingleProducerMultipleConsumerLoops.java
  38   38   * @run main/timeout=600 SingleProducerMultipleConsumerLoops
  39   39   * @summary  check ordering for blocking queues with 1 producer and multiple consumers
  40   40   */
  41   41  
  42   42  import java.util.concurrent.*;
  43   43  
  44   44  public class SingleProducerMultipleConsumerLoops {
  45   45      static final int CAPACITY =      100;
  46   46  
  47   47      static final ExecutorService pool = Executors.newCachedThreadPool();
↓ open down ↓ 18 lines elided ↑ open up ↑
  66   66              System.out.println("----------------------------------------");
  67   67              System.out.println("Consumers: " + i);
  68   68              oneTest(i, iters);
  69   69              Thread.sleep(100);
  70   70          }
  71   71          pool.shutdown();
  72   72          if (! pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS))
  73   73              throw new Error();
  74   74     }
  75   75  
  76      -    static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
  77      -        LTQasSQ() { super(); }
  78      -        public void put(T x) {
  79      -            try { super.transfer(x); }
  80      -            catch (InterruptedException ex) { throw new Error(); }
  81      -        }
  82      -        private final static long serialVersionUID = 42;
  83      -    }
  84      -
  85      -    static final class HalfSyncLTQ<T> extends LinkedTransferQueue<T> {
  86      -        HalfSyncLTQ() { super(); }
  87      -        public void put(T x) {
  88      -            if (ThreadLocalRandom.current().nextBoolean())
  89      -                super.put(x);
  90      -            else {
  91      -                try { super.transfer(x); }
  92      -                catch (InterruptedException ex) { throw new Error(); }
  93      -            }
  94      -        }
  95      -        private final static long serialVersionUID = 42;
  96      -    }
  97      -
  98   76      static void oneTest(int consumers, int iters) throws Exception {
  99   77          oneRun(new ArrayBlockingQueue<Integer>(CAPACITY), consumers, iters);
 100   78          oneRun(new LinkedBlockingQueue<Integer>(CAPACITY), consumers, iters);
 101   79          oneRun(new LinkedBlockingDeque<Integer>(CAPACITY), consumers, iters);
 102   80          oneRun(new LinkedTransferQueue<Integer>(), consumers, iters);
 103      -        oneRun(new LTQasSQ<Integer>(), consumers, iters);
 104      -        oneRun(new HalfSyncLTQ<Integer>(), consumers, iters);
 105   81          oneRun(new PriorityBlockingQueue<Integer>(), consumers, iters);
 106   82          oneRun(new SynchronousQueue<Integer>(), consumers, iters);
 107   83          if (print)
 108   84              System.out.println("fair implementations:");
 109   85          oneRun(new SynchronousQueue<Integer>(true), consumers, iters);
 110   86          oneRun(new ArrayBlockingQueue<Integer>(CAPACITY, true), consumers, iters);
 111   87      }
 112   88  
 113      -    static abstract class Stage implements Runnable {
       89 +    abstract static class Stage implements Runnable {
 114   90          final int iters;
 115   91          final BlockingQueue<Integer> queue;
 116   92          final CyclicBarrier barrier;
 117   93          volatile int result;
 118      -        Stage (BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
       94 +        Stage(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
 119   95              queue = q;
 120   96              barrier = b;
 121   97              this.iters = iters;
 122   98          }
 123   99      }
 124  100  
 125  101      static class Producer extends Stage {
 126  102          Producer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
 127  103              super(q, b, iters);
 128  104          }
↓ open down ↓ 65 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX