--- jsr166/src/test/loops/ConcurrentDequeLoops.java 2005/05/02 19:19:38 1.1 +++ jsr166/src/test/loops/ConcurrentDequeLoops.java 2009/11/02 23:42:46 1.4 @@ -1,14 +1,7 @@ /* - * @test %I% %E% - * @bug 4486658 - * @compile -source 1.5 ConcurrentDequeLoops.java - * @run main/timeout=230 ConcurrentDequeLoops - * @summary Checks that a set of threads can repeatedly get and modify items - */ -/* * Written by Doug Lea with assistance from members of JCP JSR-166 - * Expert Group and released to the public domain. Use, modify, and - * redistribute this code in any way without acknowledgement. + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/licenses/publicdomain */ import java.util.*; @@ -29,14 +22,14 @@ public class ConcurrentDequeLoops { if (args.length > 0) { try { klass = Class.forName(args[0]); - } catch(ClassNotFoundException e) { + } catch (ClassNotFoundException e) { throw new RuntimeException("Class " + args[0] + " not found."); } } - else + else throw new Error(); - if (args.length > 1) + if (args.length > 1) maxStages = Integer.parseInt(args[1]); System.out.print("Class: " + klass.getName()); @@ -56,8 +49,8 @@ public class ConcurrentDequeLoops { if (i == k) { k = i << 1; i = i + (i >>> 1); - } - else + } + else i = k; } pool.shutdown(); @@ -69,7 +62,7 @@ public class ConcurrentDequeLoops { final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom(); int items; Stage (Deque q, CyclicBarrier b, int items) { - queue = q; + queue = q; barrier = b; this.items = items; } @@ -107,7 +100,7 @@ public class ConcurrentDequeLoops { else queue.addLast(res); } - else { // spinwait + else { // spinwait for (int k = 1 + (l & 15); k != 0; --k) l = LoopHelpers.compute1(LoopHelpers.compute2(l)); if ((l & 3) == 3) { @@ -117,7 +110,7 @@ public class ConcurrentDequeLoops { } return new Integer(l); } - catch (Exception ie) { + catch (Exception ie) { ie.printStackTrace(); throw new Error("Call loop failed"); } @@ -130,7 +123,7 @@ public class ConcurrentDequeLoops { CyclicBarrier barrier = new CyclicBarrier(n + 1, timer); totalItems = new AtomicInteger(n * items); ArrayList> results = new ArrayList>(n); - for (int i = 0; i < n; ++i) + for (int i = 0; i < n; ++i) results.add(pool.submit(new Stage(q, barrier, items))); if (print) @@ -148,6 +141,6 @@ public class ConcurrentDequeLoops { System.out.println(LoopHelpers.rightJustify(time / (items * n)) + " ns per item"); if (total == 0) // avoid overoptimization System.out.println("useless result: " + total); - + } }