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 multiple producers and consumers using blocking queues
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 java.util.concurrent.atomic.AtomicInteger;
55 import jdk.testlibrary.Utils;
56
57 public class ProducerConsumerLoops {
58 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
59 static ExecutorService pool;
60
61 public static void main(String[] args) throws Exception {
62 final int maxPairs = (args.length > 0)
63 ? Integer.parseInt(args[0])
64 : 5;
65 int iters = 10000;
66
67 pool = Executors.newCachedThreadPool();
68 for (int i = 1; i <= maxPairs; i += (i+1) >>> 1) {
69 // Adjust iterations to limit typical single runs to <= 10 ms;
70 // Notably, fair queues get fewer iters.
71 // Unbounded queues can legitimately OOME if iterations
72 // high enough, but we have a sufficiently low limit here.
73 run(new ArrayBlockingQueue<Integer>(100), i, 500);
74 run(new LinkedBlockingQueue<Integer>(100), i, 1000);
75 run(new LinkedBlockingDeque<Integer>(100), i, 1000);
|
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 multiple producers and consumers using blocking queues
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 java.util.concurrent.atomic.AtomicInteger;
55 import jdk.test.lib.Utils;
56
57 public class ProducerConsumerLoops {
58 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
59 static ExecutorService pool;
60
61 public static void main(String[] args) throws Exception {
62 final int maxPairs = (args.length > 0)
63 ? Integer.parseInt(args[0])
64 : 5;
65 int iters = 10000;
66
67 pool = Executors.newCachedThreadPool();
68 for (int i = 1; i <= maxPairs; i += (i+1) >>> 1) {
69 // Adjust iterations to limit typical single runs to <= 10 ms;
70 // Notably, fair queues get fewer iters.
71 // Unbounded queues can legitimately OOME if iterations
72 // high enough, but we have a sufficiently low limit here.
73 run(new ArrayBlockingQueue<Integer>(100), i, 500);
74 run(new LinkedBlockingQueue<Integer>(100), i, 1000);
75 run(new LinkedBlockingDeque<Integer>(100), i, 1000);
|