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.9 by jsr166, Thu Dec 18 18:13:06 2014 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 130 | Line 129 | public class SingleProducerMultipleConsu
129          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters);
130  
131      }
132 <    
133 <    static abstract class Stage implements Runnable {
132 >
133 >    abstract static class Stage implements Runnable {
134          final int iters;
135          final BlockingQueue<Integer> queue;
136          final CyclicBarrier barrier;
137          volatile int result;
138 <        Stage (BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
139 <            queue = q;
138 >        Stage(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
139 >            queue = q;
140              barrier = b;
141              this.iters = iters;
142          }
# Line 160 | Line 159 | public class SingleProducerMultipleConsu
159                  barrier.await();
160                  result = 432;
161              }
162 <            catch (Exception ie) {
163 <                ie.printStackTrace();
164 <                return;
162 >            catch (Exception ie) {
163 >                ie.printStackTrace();
164 >                return;
165              }
166          }
167      }
168  
169      static class Consumer extends Stage {
170 <        Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
170 >        Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
171              super(q, b, iters);
172  
173          }
# Line 186 | Line 185 | public class SingleProducerMultipleConsu
185                  result = s;
186                  if (s == 0) System.out.print(" ");
187              }
188 <            catch (Exception ie) {
189 <                ie.printStackTrace();
190 <                return;
188 >            catch (Exception ie) {
189 >                ie.printStackTrace();
190 >                return;
191              }
192          }
193  
# Line 211 | Line 210 | public class SingleProducerMultipleConsu
210      static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
211          LTQasSQ() { super(); }
212          public void put(T x) {
213 <            try { super.transfer(x);
213 >            try { super.transfer(x);
214              } catch (InterruptedException ex) { throw new Error(); }
215          }
216      }
# Line 223 | Line 222 | public class SingleProducerMultipleConsu
222              if ((++calls & 1) == 0)
223                  super.put(x);
224              else {
225 <                try { super.transfer(x);
226 <                } catch (InterruptedException ex) {
227 <                    throw new Error();
225 >                try { super.transfer(x);
226 >                } catch (InterruptedException ex) {
227 >                    throw new Error();
228                  }
229              }
230          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines