< prev index next >

test/jdk/java/util/concurrent/BlockingQueue/SingleProducerMultipleConsumerLoops.java

Print this page
rev 51731 : imported patch 8210732


  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  */
  22 
  23 /*
  24  * This file is available under and governed by the GNU General Public
  25  * License version 2 only, as published by the Free Software Foundation.
  26  * However, the following notice accompanied the original version of this
  27  * file:
  28  *
  29  * Written by Doug Lea with assistance from members of JCP JSR-166
  30  * Expert Group and released to the public domain, as explained at
  31  * http://creativecommons.org/publicdomain/zero/1.0/
  32  */
  33 
  34 /*
  35  * @test
  36  * @bug 4486658
  37  * @summary  check ordering for blocking queues with 1 producer and multiple consumers
  38  * @library /lib/testlibrary/
  39  */
  40 
  41 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  42 import static java.util.concurrent.TimeUnit.NANOSECONDS;
  43 
  44 import java.util.concurrent.ArrayBlockingQueue;
  45 import java.util.concurrent.BlockingQueue;
  46 import java.util.concurrent.CyclicBarrier;
  47 import java.util.concurrent.ExecutorService;
  48 import java.util.concurrent.Executors;
  49 import java.util.concurrent.LinkedBlockingDeque;
  50 import java.util.concurrent.LinkedBlockingQueue;
  51 import java.util.concurrent.LinkedTransferQueue;
  52 import java.util.concurrent.PriorityBlockingQueue;
  53 import java.util.concurrent.SynchronousQueue;
  54 import jdk.testlibrary.Utils;
  55 
  56 public class SingleProducerMultipleConsumerLoops {
  57     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  58     static ExecutorService pool;
  59 
  60     public static void main(String[] args) throws Exception {
  61         final int maxConsumers = (args.length > 0)
  62             ? Integer.parseInt(args[0])
  63             : 5;
  64 
  65         pool = Executors.newCachedThreadPool();
  66         for (int i = 1; i <= maxConsumers; i += (i+1) >>> 1) {
  67             // Adjust iterations to limit typical single runs to <= 10 ms;
  68             // Notably, fair queues get fewer iters.
  69             // Unbounded queues can legitimately OOME if iterations
  70             // high enough, but we have a sufficiently low limit here.
  71             run(new ArrayBlockingQueue<Integer>(100), i, 1000);
  72             run(new LinkedBlockingQueue<Integer>(100), i, 1000);
  73             run(new LinkedBlockingDeque<Integer>(100), i, 1000);
  74             run(new LinkedTransferQueue<Integer>(), i, 700);




  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  */
  22 
  23 /*
  24  * This file is available under and governed by the GNU General Public
  25  * License version 2 only, as published by the Free Software Foundation.
  26  * However, the following notice accompanied the original version of this
  27  * file:
  28  *
  29  * Written by Doug Lea with assistance from members of JCP JSR-166
  30  * Expert Group and released to the public domain, as explained at
  31  * http://creativecommons.org/publicdomain/zero/1.0/
  32  */
  33 
  34 /*
  35  * @test
  36  * @bug 4486658
  37  * @summary  check ordering for blocking queues with 1 producer and multiple consumers
  38  * @library /test/lib
  39  */
  40 
  41 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  42 import static java.util.concurrent.TimeUnit.NANOSECONDS;
  43 
  44 import java.util.concurrent.ArrayBlockingQueue;
  45 import java.util.concurrent.BlockingQueue;
  46 import java.util.concurrent.CyclicBarrier;
  47 import java.util.concurrent.ExecutorService;
  48 import java.util.concurrent.Executors;
  49 import java.util.concurrent.LinkedBlockingDeque;
  50 import java.util.concurrent.LinkedBlockingQueue;
  51 import java.util.concurrent.LinkedTransferQueue;
  52 import java.util.concurrent.PriorityBlockingQueue;
  53 import java.util.concurrent.SynchronousQueue;
  54 import jdk.test.lib.Utils;
  55 
  56 public class SingleProducerMultipleConsumerLoops {
  57     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  58     static ExecutorService pool;
  59 
  60     public static void main(String[] args) throws Exception {
  61         final int maxConsumers = (args.length > 0)
  62             ? Integer.parseInt(args[0])
  63             : 5;
  64 
  65         pool = Executors.newCachedThreadPool();
  66         for (int i = 1; i <= maxConsumers; i += (i+1) >>> 1) {
  67             // Adjust iterations to limit typical single runs to <= 10 ms;
  68             // Notably, fair queues get fewer iters.
  69             // Unbounded queues can legitimately OOME if iterations
  70             // high enough, but we have a sufficiently low limit here.
  71             run(new ArrayBlockingQueue<Integer>(100), i, 1000);
  72             run(new LinkedBlockingQueue<Integer>(100), i, 1000);
  73             run(new LinkedBlockingDeque<Integer>(100), i, 1000);
  74             run(new LinkedTransferQueue<Integer>(), i, 700);


< prev index next >