--- jsr166/src/test/loops/UnboundedQueueFillEmptyLoops.java 2009/11/03 01:04:02 1.6 +++ jsr166/src/test/loops/UnboundedQueueFillEmptyLoops.java 2016/10/29 06:23:09 1.13 @@ -1,13 +1,11 @@ /* * 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.*; -import java.util.concurrent.*; -import java.util.concurrent.locks.*; -import java.util.concurrent.atomic.*; +import java.util.Random; +import java.util.Queue; public class UnboundedQueueFillEmptyLoops { static int maxSize = 10000; @@ -16,7 +14,7 @@ public class UnboundedQueueFillEmptyLoop static Integer[] numbers; public static void main(String[] args) throws Exception { - Class klass = null; + Class klass = null; if (args.length > 0) { try { klass = Class.forName(args[0]); @@ -42,10 +40,11 @@ public class UnboundedQueueFillEmptyLoop oneRun(klass, maxSize); if (total == 0) System.out.print(" "); - } + } - static void oneRun(Class klass, int n) throws Exception { - Queue q = (Queue) klass.newInstance(); + static void oneRun(Class klass, int n) throws Exception { + Queue q = + (Queue) klass.getConstructor().newInstance(); int sum = total; int m = rng.nextInt(numbers.length); long startTime = System.nanoTime(); @@ -55,8 +54,7 @@ public class UnboundedQueueFillEmptyLoop m = 0; q.offer(numbers[m++]); } - Integer p; - while ((p = q.poll()) != null) + for (Integer p; (p = q.poll()) != null; ) sum += p.intValue(); } total += sum;