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.3 by dl, Mon Feb 19 00:46:06 2007 UTC vs.
Revision 1.4 by dl, Fri Oct 23 19:57:06 2009 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/licenses/publicdomain
5   */
6  
7 + //import jsr166y.*;
8   import java.util.concurrent.*;
9   import java.util.concurrent.atomic.*;
10  
11   public class CachedThreadPoolLoops {
12 +    static final int NCPUS = Runtime.getRuntime().availableProcessors();
13      static final AtomicInteger remaining = new AtomicInteger();
14      static final int maxIters = 1000000;
15  
16      public static void main(String[] args) throws Exception {
17 <        int maxThreads = 100;
16 <
17 >        int maxThreads = NCPUS * 3 / 2; // 100;
18          if (args.length > 0)
19              maxThreads = Integer.parseInt(args[0]);
20  
21          System.out.print("Warmup:");
22 <        for (int j = 0; j < 2; ++j) {
22 >        for (int j = 0; j < 1; ++j) {
23              int k = 1;
24              for (int i = 1; i <= maxThreads;) {
25                  System.out.print(" " + i);
# Line 49 | Line 50 | public class CachedThreadPoolLoops {
50     }
51  
52      static void oneTest(int nThreads, int iters, boolean print) throws Exception {
53 <        //        if (print) System.out.print("LinkedBlockingQueue     ");
54 <        //        oneRun(new LinkedBlockingQueue<Runnable>(256), nThreads, iters, print);
55 <        //        if (print) System.out.print("ArrayBlockingQueue      ");
56 <        //        oneRun(new ArrayBlockingQueue<Runnable>(256), nThreads, iters, print);
57 <        if (print) System.out.print("SynchronousQueue        ");
53 >        Thread.sleep(100); // System.gc();
54 >        if (print) System.out.print("LinkedTransferQueue      ");
55 >        oneRun(new LinkedTransferQueue<Runnable>(), nThreads, iters, print);
56 >
57 >        Thread.sleep(100); // System.gc();
58 >        if (print) System.out.print("LinkedBlockingQueue      ");
59 >        oneRun(new LinkedBlockingQueue<Runnable>(), nThreads, iters, print);
60 >
61 >        Thread.sleep(100); // System.gc();
62 >        if (print) System.out.print("SynchronousQueue         ");
63          oneRun(new SynchronousQueue<Runnable>(false), nThreads, iters, print);
64 <        if (print) System.out.print("SynchronousQueue(fair)  ");
64 >
65 >        Thread.sleep(100); // System.gc();
66 >        if (print) System.out.print("SynchronousQueue(fair)   ");
67          oneRun(new SynchronousQueue<Runnable>(true), nThreads, iters, print);
68 +
69 +        Thread.sleep(100); // System.gc();
70 +        if (print) System.out.print("LinkedTransferQueue(xfer)");
71 +        oneRun(new LTQasSQ<Runnable>(), nThreads, iters, print);
72 +
73 +        Thread.sleep(100); // System.gc();
74 +        if (print) System.out.print("LinkedTransferQueue(half)");
75 +        oneRun(new HalfSyncLTQ<Runnable>(), nThreads, iters, print);
76 +
77 +        Thread.sleep(100); // System.gc();
78 +        if (print) System.out.print("ArrayBlockingQueue(256) ");
79 +        oneRun(new ArrayBlockingQueue<Runnable>(256), nThreads, iters, print);
80 +
81      }
82  
83      static final class Task implements Runnable {
# Line 110 | Line 131 | public class CachedThreadPoolLoops {
131          pool.shutdownNow();
132      }
133  
134 +    static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
135 +        LTQasSQ() { super(); }
136 +        public void put(T x) {
137 +            try { super.transfer(x);
138 +            } catch (InterruptedException ex) { throw new Error(); }
139 +        }
140 +    }
141 +
142 +    static final class HalfSyncLTQ<T> extends LinkedTransferQueue<T> {
143 +        int calls;
144 +        HalfSyncLTQ() { super(); }
145 +        public void put(T x) {
146 +            if ((++calls & 1) == 0)
147 +                super.put(x);
148 +            else {
149 +                try { super.transfer(x);
150 +                } catch (InterruptedException ex) {
151 +                    throw new Error();
152 +                }
153 +            }
154 +        }
155 +    }
156 +
157   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines