--- jsr166/src/test/loops/LockOncePerThreadLoops.java 2007/02/19 00:46:06 1.2 +++ jsr166/src/test/loops/LockOncePerThreadLoops.java 2016/12/31 04:10:36 1.7 @@ -1,12 +1,13 @@ /* * 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.*; -import java.util.concurrent.locks.*; -import java.util.*; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.locks.ReentrantLock; public final class LockOncePerThreadLoops { static final ExecutorService pool = Executors.newCachedThreadPool(); @@ -17,10 +18,10 @@ public final class LockOncePerThreadLoop static int replications = 20; public static void main(String[] args) throws Exception { - if (args.length > 0) + if (args.length > 0) replications = Integer.parseInt(args[0]); - if (args.length > 1) + if (args.length > 1) nlocks = Integer.parseInt(args[1]); print = true; @@ -48,13 +49,13 @@ public final class LockOncePerThreadLoop } final void test() throws Exception { - for (int i = 0; i < nthreads; ++i) + for (int i = 0; i < nthreads; ++i) pool.execute(this); barrier.await(); barrier.await(); if (print) { long time = timer.getTime(); - double secs = (double)(time) / 1000000000.0; + double secs = (double) time / 1000000000.0; System.out.println("\t " + secs + "s run time"); } @@ -65,7 +66,7 @@ public final class LockOncePerThreadLoop public final void run() { try { - barrier.await(); + barrier.await(); int sum = v; int x = 0; for (int i = 0; i < locks.length; ++i) { @@ -86,8 +87,8 @@ public final class LockOncePerThreadLoop barrier.await(); result += sum; } - catch (Exception ie) { - return; + catch (Exception ie) { + return; } } }