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

Comparing jsr166/src/test/loops/LockLoops.java (file contents):
Revision 1.5 by jsr166, Thu Sep 16 03:57:13 2010 UTC vs.
Revision 1.11 by jsr166, Mon Aug 10 03:13:33 2015 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   * A simple test program. Feel free to play.
8   */
9  
10 + import java.util.*;
11   import java.util.concurrent.*;
12   import java.util.concurrent.locks.*;
12 import java.util.*;
13  
14   public final class LockLoops {
15      static final ExecutorService pool = Executors.newCachedThreadPool();
# Line 18 | Line 18 | public final class LockLoops {
18      static boolean doBuiltin = true;
19      static boolean doReadWrite = true;
20      static boolean doSemaphore = true;
21 <    static boolean doFair =  true;
21 >    static boolean doFair = true;
22  
23      public static void main(String[] args) throws Exception {
24          int maxThreads = 100;
# Line 93 | Line 93 | public final class LockLoops {
93                  System.out.print("ReentrantReadWriteLock");
94              new ReentrantReadWriteLockLoop().test(v, nthreads, iters);
95              Thread.sleep(10);
96
96          }
97  
98          if (doSemaphore) {
# Line 106 | Line 105 | public final class LockLoops {
105                  System.out.print("FairSemaphore         ");
106              new FairSemaphoreLoop().test(v, nthreads, iters);
107              Thread.sleep(10);
109
108          }
109  
110          if (doFair) {
# Line 126 | Line 124 | public final class LockLoops {
124                  new FairReentrantReadWriteLockLoop().test(v, nthreads, iters);
125                  Thread.sleep(10);
126              }
129
127          }
131
128      }
129  
130 <    static abstract class LockLoop implements Runnable {
130 >    abstract static class LockLoop implements Runnable {
131          int v;
132          int iters;
133          volatile int result;
# Line 198 | Line 194 | public final class LockLoops {
194      }
195  
196      private static class NoLockVolatileLoop extends LockLoop {
197 <        volatile private int vv;
197 >        private volatile int vv;
198          final int loop(int n) {
199              int sum = 0;
200              while (n-- > 0) {
# Line 211 | Line 207 | public final class LockLoops {
207      }
208  
209      private static class ReentrantLockLoop extends LockLoop {
210 <        final private ReentrantLock lock = new ReentrantLock();
210 >        private final ReentrantLock lock = new ReentrantLock();
211          final int loop(int n) {
212              int sum = 0;
213              while (n-- > 0) {
# Line 229 | Line 225 | public final class LockLoops {
225      }
226  
227      private static class FairReentrantLockLoop extends LockLoop {
228 <        final private ReentrantLock lock = new ReentrantLock(true);
228 >        private final ReentrantLock lock = new ReentrantLock(true);
229          final int loop(int n) {
230              int sum = 0;
231              while (n-- > 0) {
# Line 247 | Line 243 | public final class LockLoops {
243      }
244  
245      private static class ReentrantWriteLockLoop extends LockLoop {
246 <        final private Lock lock = new ReentrantReadWriteLock().writeLock();
246 >        private final Lock lock = new ReentrantReadWriteLock().writeLock();
247          final int loop(int n) {
248              int sum = 0;
249              while (n-- > 0) {
# Line 265 | Line 261 | public final class LockLoops {
261      }
262  
263      private static class ReentrantReadWriteLockLoop extends LockLoop {
264 <        final private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
264 >        private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
265          final int loop(int n) {
266              int sum = 0;
267              while (n-- > 0) {
# Line 309 | Line 305 | public final class LockLoops {
305      }
306  
307      private static class SemaphoreLoop extends LockLoop {
308 <        final private Semaphore sem = new Semaphore(1, false);
308 >        private final Semaphore sem = new Semaphore(1, false);
309          final int loop(int n) {
310              int sum = 0;
311              try {
# Line 331 | Line 327 | public final class LockLoops {
327          }
328      }
329      private static class FairSemaphoreLoop extends LockLoop {
330 <        final private Semaphore sem = new Semaphore(1, true);
330 >        private final Semaphore sem = new Semaphore(1, true);
331          final int loop(int n) {
332              int sum = 0;
333              try {
# Line 354 | Line 350 | public final class LockLoops {
350      }
351  
352      private static class FairReentrantReadWriteLockLoop extends LockLoop {
353 <        final private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
353 >        private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
354          final int loop(int n) {
355              int sum = 0;
356              while (n-- > 0) {
# Line 378 | Line 374 | public final class LockLoops {
374              return sum;
375          }
376      }
381
382
377   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines