--- jsr166/src/test/loops/ExecutorCompletionServiceLoops.java 2007/02/19 00:46:06 1.2 +++ jsr166/src/test/loops/ExecutorCompletionServiceLoops.java 2015/10/28 06:30:10 1.8 @@ -1,16 +1,16 @@ /* * 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 ExecutorCompletionServiceLoops { - static final int POOLSIZE = 100; - static final ExecutorService pool = + static final int POOLSIZE = 100; + static final ExecutorService pool = Executors.newFixedThreadPool(POOLSIZE); - static final ExecutorCompletionService ecs = + static final ExecutorCompletionService ecs = new ExecutorCompletionService(pool); static boolean print = false; @@ -18,22 +18,22 @@ public class ExecutorCompletionServiceLo int max = 8; int base = 10000; - if (args.length > 0) + if (args.length > 0) max = Integer.parseInt(args[0]); System.out.println("Warmup..."); oneTest( base ); Thread.sleep(100); print = true; - + for (int i = 1; i <= max; i += (i+1) >>> 1) { System.out.print("n: " + i * base); oneTest(i * base ); Thread.sleep(100); } pool.shutdown(); - } - + } + static class Task implements Callable { public Integer call() { int l = System.identityHashCode(this); @@ -48,9 +48,9 @@ public class ExecutorCompletionServiceLo static class Producer implements Runnable { final ExecutorCompletionService cs; final int iters; - Producer(ExecutorCompletionService ecs, int i) { + Producer(ExecutorCompletionService ecs, int i) { cs = ecs; - iters = i; + iters = i; } public void run() { for (int i = 0; i < iters; ++i) @@ -74,8 +74,6 @@ public class ExecutorCompletionServiceLo if (r == 0) // avoid overoptimization System.out.println("useless result: " + r); - - } }