--- jsr166/src/test/loops/CancelledProducerConsumerLoops.java 2009/11/02 23:42:46 1.7 +++ jsr166/src/test/loops/CancelledProducerConsumerLoops.java 2015/10/28 06:30:09 1.16 @@ -1,12 +1,12 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ import java.util.concurrent.*; public class CancelledProducerConsumerLoops { - static final int CAPACITY = 100; + static final int CAPACITY = 100; static final long TIMEOUT = 100; static final ExecutorService pool = Executors.newCachedThreadPool(); @@ -32,13 +32,13 @@ public class CancelledProducerConsumerLo Thread.sleep(100); } pool.shutdown(); - } + } static void oneRun(BlockingQueue q, int npairs, int iters) throws Exception { LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer(); CyclicBarrier barrier = new CyclicBarrier(npairs * 2 + 1, timer); - Future[] prods = new Future[npairs]; - Future[] cons = new Future[npairs]; + Future[] prods = new Future[npairs]; + Future[] cons = new Future[npairs]; for (int i = 0; i < npairs; ++i) { prods[i] = pool.submit(new Producer(q, barrier, iters)); @@ -72,7 +72,7 @@ public class CancelledProducerConsumerLo long endTime = System.nanoTime(); long time = endTime - timer.startTime; if (print) { - double secs = (double)(time) / 1000000000.0; + double secs = (double) time / 1000000000.0; System.out.println("\t " + secs + "s run time"); } } @@ -95,7 +95,6 @@ public class CancelledProducerConsumerLo System.out.print("SynchronousQueue "); oneRun(new SynchronousQueue(), pairs, iters / 8); - if (print) System.out.print("SynchronousQueue(fair) "); oneRun(new SynchronousQueue(true), pairs, iters / 8); @@ -107,11 +106,11 @@ public class CancelledProducerConsumerLo */ } - static abstract class Stage implements Callable { + abstract static class Stage implements Callable { final BlockingQueue queue; final CyclicBarrier barrier; final int iters; - Stage (BlockingQueue q, CyclicBarrier b, int iters) { + Stage(BlockingQueue q, CyclicBarrier b, int iters) { queue = q; barrier = b; this.iters = iters; @@ -156,6 +155,4 @@ public class CancelledProducerConsumerLo return new Integer(s); } } - - }