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.*; |
9 |
– |
import java.util.*; |
10 |
|
|
11 |
|
/** |
12 |
|
* Measures repeated futile timed attempts to acquire a ReentrantLock. |
51 |
|
continue nextArg; |
52 |
|
} |
53 |
|
} |
54 |
< |
throw new Error("Usage: FutileTimedTryLockLoops minThreads=n maxThreads=n Threads=n nanos=n iters=n"); |
54 |
> |
throw new Error("Usage: FutileTimedTryLockLoops minThreads=n maxThreads=n threads=n nanos=n iters=n"); |
55 |
|
} |
56 |
|
final ExecutorService pool = Executors.newCachedThreadPool(); |
57 |
|
final ReentrantLock lock = new ReentrantLock(); |
59 |
|
lock.lock(); |
60 |
|
|
61 |
|
for (int i = minThreads; i <= maxThreads; i += (i+1) >>> 1) { |
62 |
+ |
// warmup |
63 |
+ |
if (i == minThreads) |
64 |
+ |
pool.invokeAll(Collections.nCopies(i, task)); |
65 |
+ |
|
66 |
|
long startTime = System.nanoTime(); |
67 |
|
pool.invokeAll(Collections.nCopies(i, task)); |
68 |
|
long elapsed = System.nanoTime() - startTime; |