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

Comparing jsr166/src/test/loops/ConcurrentQueueLoops.java (file contents):
Revision 1.11 by jsr166, Wed Sep 1 07:47:27 2010 UTC vs.
Revision 1.19 by jsr166, Sat Dec 31 19:02:43 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.ArrayList;
8 > import java.util.Queue;
9 > import java.util.concurrent.Callable;
10 > import java.util.concurrent.CyclicBarrier;
11 > import java.util.concurrent.ExecutorService;
12 > import java.util.concurrent.Executors;
13 > import java.util.concurrent.Future;
14  
15   public class ConcurrentQueueLoops {
16      static final ExecutorService pool = Executors.newCachedThreadPool();
# Line 21 | Line 24 | public class ConcurrentQueueLoops {
24      public static void main(String[] args) throws Exception {
25          int maxStages = 100;
26          int work = 1024;
27 <        Class klass = null;
27 >        Class<?> klass = null;
28          if (args.length > 0) {
29              try {
30                  klass = Class.forName(args[0]);
# Line 50 | Line 53 | public class ConcurrentQueueLoops {
53          Thread.sleep(100);
54          print = true;
55  
56 <        int k = 1;
54 <        for (int i = 1; i <= maxStages;) {
56 >        for (int k = 1, i = 1; i <= maxStages;) {
57              oneRun(klass, i);
58              if (i == k) {
59                  k = i << 1;
# Line 61 | Line 63 | public class ConcurrentQueueLoops {
63                  i = k;
64          }
65          pool.shutdown();
66 <   }
66 >    }
67  
68      static final class Stage implements Callable<Integer> {
69          final Queue<Integer> queue;
# Line 76 | Line 78 | public class ConcurrentQueueLoops {
78          static int compute(int l) {
79              if (l == 0)
80                  return (int) System.nanoTime();
81 <            int nn =  (l >>> 7) & workMask;
81 >            int nn = (l >>> 7) & workMask;
82              while (nn-- > 0)
83                  l = LoopHelpers.compute6(l);
84              return l;
# Line 117 | Line 119 | public class ConcurrentQueueLoops {
119          }
120      }
121  
122 <    static void oneRun(Class klass, int n) throws Exception {
123 <        Queue<Integer> q = (Queue<Integer>) klass.newInstance();
122 >    static void oneRun(Class<?> klass, int n) throws Exception {
123 >        Queue<Integer> q =
124 >            (Queue<Integer>) klass.getConstructor().newInstance();
125          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
126          CyclicBarrier barrier = new CyclicBarrier(n + 1, timer);
127          ArrayList<Future<Integer>> results = new ArrayList<Future<Integer>>(n);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines