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 Checks for responsiveness of blocking queues to cancellation.
38 * @library /lib/testlibrary/
39 */
40
41 import static java.util.concurrent.TimeUnit.MILLISECONDS;
42
43 import java.util.ArrayList;
44 import java.util.List;
45 import java.util.concurrent.ArrayBlockingQueue;
46 import java.util.concurrent.BlockingQueue;
47 import java.util.concurrent.Callable;
48 import java.util.concurrent.CancellationException;
49 import java.util.concurrent.CountDownLatch;
50 import java.util.concurrent.CyclicBarrier;
51 import java.util.concurrent.ExecutorService;
52 import java.util.concurrent.Executors;
53 import java.util.concurrent.Future;
54 import java.util.concurrent.LinkedBlockingDeque;
55 import java.util.concurrent.LinkedBlockingQueue;
56 import java.util.concurrent.SynchronousQueue;
57 import java.util.concurrent.ThreadLocalRandom;
58 import java.util.concurrent.TimeUnit;
59 import jdk.testlibrary.Utils;
60
61 public class CancelledProducerConsumerLoops {
62 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
63 static ExecutorService pool;
64
65 public static void main(String[] args) throws Exception {
66 final int maxPairs = (args.length > 0) ? Integer.parseInt(args[0]) : 5;
67
68 pool = Executors.newCachedThreadPool();
69 for (int i = 1; i <= maxPairs; i += (i+1) >>> 1) {
70 final List<BlockingQueue<Integer>> queues = new ArrayList<>();
71 queues.add(new ArrayBlockingQueue<Integer>(100));
72 queues.add(new LinkedBlockingQueue<Integer>(100));
73 queues.add(new LinkedBlockingDeque<Integer>(100));
74 queues.add(new SynchronousQueue<Integer>());
75 // unbounded queue implementations are prone to OOME:
76 // PriorityBlockingQueue, LinkedTransferQueue
77 for (BlockingQueue<Integer> queue : queues)
78 new CancelledProducerConsumerLoops(i, queue).run();
79 }
|
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 Checks for responsiveness of blocking queues to cancellation.
38 * @library /test/lib
39 */
40
41 import static java.util.concurrent.TimeUnit.MILLISECONDS;
42
43 import java.util.ArrayList;
44 import java.util.List;
45 import java.util.concurrent.ArrayBlockingQueue;
46 import java.util.concurrent.BlockingQueue;
47 import java.util.concurrent.Callable;
48 import java.util.concurrent.CancellationException;
49 import java.util.concurrent.CountDownLatch;
50 import java.util.concurrent.CyclicBarrier;
51 import java.util.concurrent.ExecutorService;
52 import java.util.concurrent.Executors;
53 import java.util.concurrent.Future;
54 import java.util.concurrent.LinkedBlockingDeque;
55 import java.util.concurrent.LinkedBlockingQueue;
56 import java.util.concurrent.SynchronousQueue;
57 import java.util.concurrent.ThreadLocalRandom;
58 import java.util.concurrent.TimeUnit;
59 import jdk.test.lib.Utils;
60
61 public class CancelledProducerConsumerLoops {
62 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
63 static ExecutorService pool;
64
65 public static void main(String[] args) throws Exception {
66 final int maxPairs = (args.length > 0) ? Integer.parseInt(args[0]) : 5;
67
68 pool = Executors.newCachedThreadPool();
69 for (int i = 1; i <= maxPairs; i += (i+1) >>> 1) {
70 final List<BlockingQueue<Integer>> queues = new ArrayList<>();
71 queues.add(new ArrayBlockingQueue<Integer>(100));
72 queues.add(new LinkedBlockingQueue<Integer>(100));
73 queues.add(new LinkedBlockingDeque<Integer>(100));
74 queues.add(new SynchronousQueue<Integer>());
75 // unbounded queue implementations are prone to OOME:
76 // PriorityBlockingQueue, LinkedTransferQueue
77 for (BlockingQueue<Integer> queue : queues)
78 new CancelledProducerConsumerLoops(i, queue).run();
79 }
|