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

Comparing jsr166/src/test/loops/CancelledProducerConsumerLoops.java (file contents):
Revision 1.7 by jsr166, Mon Nov 2 23:42:46 2009 UTC vs.
Revision 1.17 by jsr166, Sat Dec 31 19:16:42 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 < import java.util.concurrent.*;
6 >
7 > import java.util.concurrent.BrokenBarrierException;
8 > import java.util.concurrent.Callable;
9 > import java.util.concurrent.CyclicBarrier;
10 > import java.util.concurrent.ExecutorService;
11 > import java.util.concurrent.Executors;
12 > import java.util.concurrent.ArrayBlockingQueue;
13 > import java.util.concurrent.BlockingQueue;
14 > import java.util.concurrent.Future;
15 > import java.util.concurrent.LinkedBlockingQueue;
16 > import java.util.concurrent.LinkedTransferQueue;
17 > import java.util.concurrent.SynchronousQueue;
18 > import java.util.concurrent.TimeUnit;
19  
20   public class CancelledProducerConsumerLoops {
21 <    static final int CAPACITY =      100;
21 >    static final int CAPACITY = 100;
22      static final long TIMEOUT = 100;
23  
24      static final ExecutorService pool = Executors.newCachedThreadPool();
# Line 32 | Line 44 | public class CancelledProducerConsumerLo
44              Thread.sleep(100);
45          }
46          pool.shutdown();
47 <   }
47 >    }
48  
49      static void oneRun(BlockingQueue<Integer> q, int npairs, int iters) throws Exception {
50          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
51          CyclicBarrier barrier = new CyclicBarrier(npairs * 2 + 1, timer);
52 <        Future[] prods = new Future[npairs];
53 <        Future[] cons = new Future[npairs];
52 >        Future<?>[] prods = new Future<?>[npairs];
53 >        Future<?>[] cons = new Future<?>[npairs];
54  
55          for (int i = 0; i < npairs; ++i) {
56              prods[i] = pool.submit(new Producer(q, barrier, iters));
# Line 72 | Line 84 | public class CancelledProducerConsumerLo
84          long endTime = System.nanoTime();
85          long time = endTime - timer.startTime;
86          if (print) {
87 <            double secs = (double)(time) / 1000000000.0;
87 >            double secs = (double) time / 1000000000.0;
88              System.out.println("\t " + secs + "s run time");
89          }
90      }
# Line 95 | Line 107 | public class CancelledProducerConsumerLo
107              System.out.print("SynchronousQueue        ");
108          oneRun(new SynchronousQueue<Integer>(), pairs, iters / 8);
109  
98
110          if (print)
111              System.out.print("SynchronousQueue(fair)  ");
112          oneRun(new SynchronousQueue<Integer>(true), pairs, iters / 8);
# Line 107 | Line 118 | public class CancelledProducerConsumerLo
118          */
119      }
120  
121 <    static abstract class Stage implements Callable {
121 >    abstract static class Stage implements Callable {
122          final BlockingQueue<Integer> queue;
123          final CyclicBarrier barrier;
124          final int iters;
125 <        Stage (BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
125 >        Stage(BlockingQueue<Integer> q, CyclicBarrier b, int iters) {
126              queue = q;
127              barrier = b;
128              this.iters = iters;
# Line 156 | Line 167 | public class CancelledProducerConsumerLo
167              return new Integer(s);
168          }
169      }
159
160
170   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines