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(); |
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; |
93 |
|
System.out.print("ReentrantReadWriteLock"); |
94 |
|
new ReentrantReadWriteLockLoop().test(v, nthreads, iters); |
95 |
|
Thread.sleep(10); |
96 |
– |
|
96 |
|
} |
97 |
|
|
98 |
|
if (doSemaphore) { |
105 |
|
System.out.print("FairSemaphore "); |
106 |
|
new FairSemaphoreLoop().test(v, nthreads, iters); |
107 |
|
Thread.sleep(10); |
109 |
– |
|
108 |
|
} |
109 |
|
|
110 |
|
if (doFair) { |
124 |
|
new FairReentrantReadWriteLockLoop().test(v, nthreads, iters); |
125 |
|
Thread.sleep(10); |
126 |
|
} |
129 |
– |
|
127 |
|
} |
131 |
– |
|
128 |
|
} |
129 |
|
|
130 |
|
abstract static class LockLoop implements Runnable { |
374 |
|
return sum; |
375 |
|
} |
376 |
|
} |
381 |
– |
|
382 |
– |
|
377 |
|
} |