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

Comparing jsr166/src/test/loops/SingleProducerMultipleConsumerLoops.java (file contents):
Revision 1.3 by dl, Fri Oct 23 19:57:07 2009 UTC vs.
Revision 1.10 by jsr166, Mon Aug 10 03:13:33 2015 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.concurrent.*;
# Line 22 | Line 22 | public class SingleProducerMultipleConsu
22      static final int POOL_MASK = POOL_SIZE-1;
23      static final Integer[] intPool = new Integer[POOL_SIZE];
24      static {
25 <        for (int i = 0; i < POOL_SIZE; ++i)
25 >        for (int i = 0; i < POOL_SIZE; ++i)
26              intPool[i] = Integer.valueOf(i);
27      }
28  
29      public static void main(String[] args) throws Exception {
30          int maxn = 12;
31  
32 <        if (args.length > 0)
32 >        if (args.length > 0)
33              maxn = Integer.parseInt(args[0]);
34  
35          print = false;
36          warmup();
37          print = true;
38  
39 <        int k = 1;
40 <        for (int i = 1; i <= maxn;) {
39 >        for (int k = 1, i = 1; i <= maxn;) {
40              System.out.println("Consumers:" + i);
41              oneTest(i, ITERS);
42              if (i == k) {
43                  k = i << 1;
44                  i = i + (i >>> 1);
45 <            }
46 <            else
45 >            }
46 >            else
47                  i = k;
48          }
49 <        
49 >
50          pool.shutdown();
51 <   }
51 >    }
52  
53      static void warmup() throws Exception {
54          print = false;
55          System.out.print("Warmup ");
56          int it = 2000;
57          for (int j = 5; j > 0; --j) {
58 <            oneTest(j, it);
58 >            oneTest(j, it);
59              System.out.print(".");
60              it += 1000;
61          }
62          System.gc();
63          it = 20000;
64          for (int j = 5; j > 0; --j) {
65 <            oneTest(j, it);
65 >            oneTest(j, it);
66              System.out.print(".");
67              it += 10000;
68          }
# Line 93 | Line 92 | public class SingleProducerMultipleConsu
92          if (print)
93              System.out.print("LinkedBlockingDeque     ");
94          oneRun(new LinkedBlockingDeque<Integer>(), n, iters);
95 <        
95 >
96          Thread.sleep(100); // System.gc();
97          if (print)
98              System.out.print("ArrayBlockingQueue      ");
# Line 103 | Line 102 | public class SingleProducerMultipleConsu
102          if (print)
103              System.out.print("SynchronousQueue        ");
104          oneRun(new SynchronousQueue<Integer>(), n, iters);
105 <        
105 >
106          Thread.sleep(100); // System.gc();
107          if (print)
108              System.out.print("SynchronousQueue(fair)  ");
# Line 118 | Line 117 | public class SingleProducerMultipleConsu
117          if (print)
118              System.out.print("LinkedTransferQueue(half)");
119          oneRun(new HalfSyncLTQ<Integer>(), n, iters);
120 <        
120 >
121          Thread.sleep(100); // System.gc();
122          if (print)
123              System.out.print("PriorityBlockingQueue   ");
# Line 128 | Line 127 | public class SingleProducerMultipleConsu
127          if (print)
128              System.out.print("ArrayBlockingQueue(fair)");
129          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters);
131
130      }
131 <    
132 <    static abstract class Stage implements Runnable {
131 >
132 >    abstract static class Stage implements Runnable {
133          final int iters;
134          final BlockingQueue<Integer> queue;
135          final CyclicBarrier barrier;
136          volatile int result;
137 <        Stage (BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
138 <            queue = q;
137 >        Stage(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
138 >            queue = q;
139              barrier = b;
140              this.iters = iters;
141          }
# Line 160 | Line 158 | public class SingleProducerMultipleConsu
158                  barrier.await();
159                  result = 432;
160              }
161 <            catch (Exception ie) {
162 <                ie.printStackTrace();
163 <                return;
161 >            catch (Exception ie) {
162 >                ie.printStackTrace();
163 >                return;
164              }
165          }
166      }
167  
168      static class Consumer extends Stage {
169 <        Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
169 >        Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
170              super(q, b, iters);
173
171          }
172  
173          public void run() {
# Line 186 | Line 183 | public class SingleProducerMultipleConsu
183                  result = s;
184                  if (s == 0) System.out.print(" ");
185              }
186 <            catch (Exception ie) {
187 <                ie.printStackTrace();
188 <                return;
186 >            catch (Exception ie) {
187 >                ie.printStackTrace();
188 >                return;
189              }
190          }
191  
# Line 211 | Line 208 | public class SingleProducerMultipleConsu
208      static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
209          LTQasSQ() { super(); }
210          public void put(T x) {
211 <            try { super.transfer(x);
211 >            try { super.transfer(x);
212              } catch (InterruptedException ex) { throw new Error(); }
213          }
214      }
# Line 223 | Line 220 | public class SingleProducerMultipleConsu
220              if ((++calls & 1) == 0)
221                  super.put(x);
222              else {
223 <                try { super.transfer(x);
224 <                } catch (InterruptedException ex) {
225 <                    throw new Error();
223 >                try { super.transfer(x);
224 >                } catch (InterruptedException ex) {
225 >                    throw new Error();
226                  }
227              }
228          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines