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.4 by jsr166, Thu Oct 29 23:09:08 2009 UTC

# 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;
# Line 43 | Line 43 | public class SingleProducerMultipleConsu
43              if (i == k) {
44                  k = i << 1;
45                  i = i + (i >>> 1);
46 <            }
47 <            else
46 >            }
47 >            else
48                  i = k;
49          }
50 <        
50 >
51          pool.shutdown();
52     }
53  
# Line 56 | Line 56 | public class SingleProducerMultipleConsu
56          System.out.print("Warmup ");
57          int it = 2000;
58          for (int j = 5; j > 0; --j) {
59 <            oneTest(j, it);
59 >            oneTest(j, it);
60              System.out.print(".");
61              it += 1000;
62          }
63          System.gc();
64          it = 20000;
65          for (int j = 5; j > 0; --j) {
66 <            oneTest(j, it);
66 >            oneTest(j, it);
67              System.out.print(".");
68              it += 10000;
69          }
# Line 93 | Line 93 | public class SingleProducerMultipleConsu
93          if (print)
94              System.out.print("LinkedBlockingDeque     ");
95          oneRun(new LinkedBlockingDeque<Integer>(), n, iters);
96 <        
96 >
97          Thread.sleep(100); // System.gc();
98          if (print)
99              System.out.print("ArrayBlockingQueue      ");
# Line 103 | Line 103 | public class SingleProducerMultipleConsu
103          if (print)
104              System.out.print("SynchronousQueue        ");
105          oneRun(new SynchronousQueue<Integer>(), n, iters);
106 <        
106 >
107          Thread.sleep(100); // System.gc();
108          if (print)
109              System.out.print("SynchronousQueue(fair)  ");
# Line 118 | Line 118 | public class SingleProducerMultipleConsu
118          if (print)
119              System.out.print("LinkedTransferQueue(half)");
120          oneRun(new HalfSyncLTQ<Integer>(), n, iters);
121 <        
121 >
122          Thread.sleep(100); // System.gc();
123          if (print)
124              System.out.print("PriorityBlockingQueue   ");
# Line 130 | Line 130 | public class SingleProducerMultipleConsu
130          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters);
131  
132      }
133 <    
133 >
134      static abstract class Stage implements Runnable {
135          final int iters;
136          final BlockingQueue<Integer> queue;
137          final CyclicBarrier barrier;
138          volatile int result;
139          Stage (BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
140 <            queue = q;
140 >            queue = q;
141              barrier = b;
142              this.iters = iters;
143          }
# Line 160 | Line 160 | public class SingleProducerMultipleConsu
160                  barrier.await();
161                  result = 432;
162              }
163 <            catch (Exception ie) {
164 <                ie.printStackTrace();
165 <                return;
163 >            catch (Exception ie) {
164 >                ie.printStackTrace();
165 >                return;
166              }
167          }
168      }
169  
170      static class Consumer extends Stage {
171 <        Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
171 >        Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
172              super(q, b, iters);
173  
174          }
# Line 186 | Line 186 | public class SingleProducerMultipleConsu
186                  result = s;
187                  if (s == 0) System.out.print(" ");
188              }
189 <            catch (Exception ie) {
190 <                ie.printStackTrace();
191 <                return;
189 >            catch (Exception ie) {
190 >                ie.printStackTrace();
191 >                return;
192              }
193          }
194  
# Line 211 | Line 211 | public class SingleProducerMultipleConsu
211      static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
212          LTQasSQ() { super(); }
213          public void put(T x) {
214 <            try { super.transfer(x);
214 >            try { super.transfer(x);
215              } catch (InterruptedException ex) { throw new Error(); }
216          }
217      }
# Line 223 | Line 223 | public class SingleProducerMultipleConsu
223              if ((++calls & 1) == 0)
224                  super.put(x);
225              else {
226 <                try { super.transfer(x);
227 <                } catch (InterruptedException ex) {
228 <                    throw new Error();
226 >                try { super.transfer(x);
227 >                } catch (InterruptedException ex) {
228 >                    throw new Error();
229                  }
230              }
231          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines