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

Comparing jsr166/src/test/loops/CachedThreadPoolLoops.java (file contents):
Revision 1.1 by dl, Tue May 31 15:08:32 2005 UTC vs.
Revision 1.2 by dl, Sun Aug 7 19:25:55 2005 UTC

# Line 16 | Line 16 | public class CachedThreadPoolLoops {
16  
17          if (args.length > 0)
18              maxThreads = Integer.parseInt(args[0]);
19 <        
19 >
20 >        System.out.print("Warmup:");
21 >        for (int j = 0; j < 2; ++j) {
22 >            int k = 1;
23 >            for (int i = 1; i <= maxThreads;) {
24 >                System.out.print(" " + i);
25 >                oneTest(i, 10000, false);
26 >                Thread.sleep(100);
27 >                if (i == k) {
28 >                    k = i << 1;
29 >                    i = i + (i >>> 1);
30 >                }
31 >                else
32 >                    i = k;
33 >            }
34 >        }
35 >        System.out.println();
36 >
37          int k = 1;
38          for (int i = 1; i <= maxThreads;) {
39              System.out.println("Threads:" + i);
40 <            oneTest(i);
40 >            oneTest(i, maxIters, true);
41              Thread.sleep(100);
42              if (i == k) {
43                  k = i << 1;
# Line 31 | Line 48 | public class CachedThreadPoolLoops {
48          }
49     }
50  
51 <    static void oneTest(int nThreads) throws Exception {
52 <        System.out.print("SynchronousQueue        ");
53 <        oneRun(new SynchronousQueue<Runnable>(), nThreads);
54 <        System.out.print("SynchronousQueue(fair)  ");
55 <        oneRun(new SynchronousQueue<Runnable>(true), nThreads);
51 >    static void oneTest(int nThreads, int iters, boolean print) throws Exception {
52 >        if (print) System.out.print("SynchronousQueue        ");
53 >        oneRun(new SynchronousQueue<Runnable>(false), nThreads, iters, print);
54 >        if (print) System.out.print("SynchronousQueue(fair)  ");
55 >        oneRun(new SynchronousQueue<Runnable>(true), nThreads, iters, print);
56      }
57  
58      static final class Task implements Runnable {
# Line 66 | Line 83 | public class CachedThreadPoolLoops {
83          }
84      }
85      
86 <    static void oneRun(BlockingQueue<Runnable> q, int nThreads) throws Exception {
86 >    static void oneRun(BlockingQueue<Runnable> q, int nThreads, int iters, boolean print) throws Exception {
87        
88          ThreadPoolExecutor pool =
89              new ThreadPoolExecutor(nThreads+1, Integer.MAX_VALUE,
90                                     1L, TimeUnit.SECONDS, q);
91  
92 <        CountDownLatch done = new CountDownLatch(maxIters);
92 >        CountDownLatch done = new CountDownLatch(iters);
93          remaining.set(nThreads-1);
94          pool.prestartAllCoreThreads();
95          Task t = new Task(pool, done);
# Line 80 | Line 97 | public class CachedThreadPoolLoops {
97          pool.execute(t);
98          done.await();
99          long time = System.nanoTime() - start;
100 <        System.out.println("\t: " + LoopHelpers.rightJustify(time / maxIters) + " ns per task");
100 >        if (print)
101 >            System.out.println("\t: " + LoopHelpers.rightJustify(time / iters) + " ns per task");
102 >        q.clear();
103 >        Thread.sleep(100);
104 >        pool.shutdown();
105 >        Thread.sleep(100);
106          pool.shutdownNow();
107      }
108  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines