ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/UnboundedQueueFillEmptyLoops.java
(Generate patch)

Comparing jsr166/src/test/loops/UnboundedQueueFillEmptyLoops.java (file contents):
Revision 1.3 by jsr166, Thu Oct 29 23:09:08 2009 UTC vs.
Revision 1.13 by jsr166, Sat Oct 29 06:23:09 2016 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import java.util.*;
8 < import java.util.concurrent.*;
9 < import java.util.concurrent.locks.*;
10 < import java.util.concurrent.atomic.*;
7 > import java.util.Random;
8 > import java.util.Queue;
9  
10   public class UnboundedQueueFillEmptyLoops {
11      static int maxSize = 10000;
# Line 16 | Line 14 | public class UnboundedQueueFillEmptyLoop
14      static Integer[] numbers;
15  
16      public static void main(String[] args) throws Exception {
17 <        Class klass = null;
17 >        Class<?> klass = null;
18          if (args.length > 0) {
19              try {
20                  klass = Class.forName(args[0]);
21 <            } catch(ClassNotFoundException e) {
21 >            } catch (ClassNotFoundException e) {
22                  throw new RuntimeException("Class " + args[0] + " not found.");
23              }
24          }
# Line 42 | Line 40 | public class UnboundedQueueFillEmptyLoop
40          oneRun(klass, maxSize);
41  
42          if (total == 0) System.out.print(" ");
43 <   }
43 >    }
44  
45 <    static void oneRun(Class klass, int n) throws Exception {
46 <        Queue<Integer> q = (Queue<Integer>)klass.newInstance();
45 >    static void oneRun(Class<?> klass, int n) throws Exception {
46 >        Queue<Integer> q =
47 >            (Queue<Integer>) klass.getConstructor().newInstance();
48          int sum = total;
49          int m = rng.nextInt(numbers.length);
50          long startTime = System.nanoTime();
# Line 55 | Line 54 | public class UnboundedQueueFillEmptyLoop
54                      m = 0;
55                  q.offer(numbers[m++]);
56              }
57 <            Integer p;
59 <            while ((p = q.poll()) != null)
57 >            for (Integer p; (p = q.poll()) != null; )
58                  sum += p.intValue();
59          }
60          total += sum;
61          long endTime = System.nanoTime();
62          long time = endTime - startTime;
63 <        double secs = (double)(time) / 1000000000.0;
63 >        double secs = (double) time / 1000000000.0;
64          System.out.println("Time: " + secs);
65      }
66  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines