ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/ProducerConsumerLoops.java
(Generate patch)

Comparing jsr166/src/test/loops/ProducerConsumerLoops.java (file contents):
Revision 1.4 by jsr166, Thu Oct 29 23:09:08 2009 UTC vs.
Revision 1.14 by jsr166, Sat Dec 31 21:34:47 2016 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import java.util.*;
8 < import java.util.concurrent.*;
9 < //import jsr166y.*;
7 > import java.util.concurrent.ArrayBlockingQueue;
8 > import java.util.concurrent.BlockingQueue;
9 > import java.util.concurrent.CyclicBarrier;
10 > import java.util.concurrent.ExecutorService;
11 > import java.util.concurrent.Executors;
12 > import java.util.concurrent.LinkedBlockingDeque;
13 > import java.util.concurrent.LinkedBlockingQueue;
14 > import java.util.concurrent.LinkedTransferQueue;
15 > import java.util.concurrent.Phaser;
16 > import java.util.concurrent.PriorityBlockingQueue;
17 > import java.util.concurrent.SynchronousQueue;
18  
19   public class ProducerConsumerLoops {
20      static final int NCPUS = Runtime.getRuntime().availableProcessors();
13    static final Random rng = new Random();
21      static final ExecutorService pool = Executors.newCachedThreadPool();
22      static boolean print = false;
23      static int producerSum;
# Line 54 | Line 61 | public class ProducerConsumerLoops {
61  
62          warmup();
63          print = true;
64 <        int k = 1;
58 <        for (int i = 1; i <= maxPairs;) {
64 >        for (int k = 1, i = 1; i <= maxPairs;) {
65              System.out.println("Pairs:" + i);
66              oneTest(i, ITERS);
67              if (i == k) {
# Line 121 | Line 127 | public class ProducerConsumerLoops {
127              System.out.print("SynchronousQueue        ");
128          oneRun(new SynchronousQueue<Integer>(), n, iters);
129  
124
130          Thread.sleep(100); // System.gc();
131          if (print)
132              System.out.print("SynchronousQueue(fair)  ");
# Line 146 | Line 151 | public class ProducerConsumerLoops {
151          if (print)
152              System.out.print("ArrayBlockingQueue(fair)");
153          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters);
149
154      }
155  
156 <    static abstract class Stage implements Runnable {
156 >    abstract static class Stage implements Runnable {
157          final int iters;
158          final BlockingQueue<Integer> queue;
159          final CyclicBarrier barrier;
160          final Phaser lagPhaser;
161 <        Stage (BlockingQueue<Integer> q, CyclicBarrier b, Phaser s,
158 <               int iters) {
161 >        Stage(BlockingQueue<Integer> q, CyclicBarrier b, Phaser s, int iters) {
162              queue = q;
163              barrier = b;
164              lagPhaser = s;
# Line 240 | Line 243 | public class ProducerConsumerLoops {
243      static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
244          LTQasSQ() { super(); }
245          public void put(T x) {
246 <            try { super.transfer(x);
247 <            } catch (InterruptedException ex) { throw new Error(); }
246 >            try { super.transfer(x); }
247 >            catch (InterruptedException ex) { throw new Error(ex); }
248          }
249      }
250  
# Line 252 | Line 255 | public class ProducerConsumerLoops {
255              if ((++calls & 1) == 0)
256                  super.put(x);
257              else {
258 <                try { super.transfer(x);
259 <                } catch (InterruptedException ex) {
257 <                    throw new Error();
258 <                }
258 >                try { super.transfer(x); }
259 >                catch (InterruptedException ex) { throw new Error(ex); }
260              }
261          }
262      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines