4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import java.util.concurrent.*; |
8 |
< |
import java.util.concurrent.locks.*; |
9 |
< |
import java.util.*; |
7 |
> |
import java.util.Collections; |
8 |
> |
import java.util.concurrent.Callable; |
9 |
> |
import java.util.concurrent.CyclicBarrier; |
10 |
> |
import java.util.concurrent.ExecutorService; |
11 |
> |
import java.util.concurrent.Executors; |
12 |
> |
import java.util.concurrent.TimeUnit; |
13 |
> |
import java.util.concurrent.locks.ReentrantLock; |
14 |
|
|
15 |
|
/** |
16 |
|
* Measures repeated futile timed attempts to acquire a ReentrantLock. |
55 |
|
continue nextArg; |
56 |
|
} |
57 |
|
} |
58 |
< |
throw new Error("Usage: FutileTimedTryLockLoops minThreads=n maxThreads=n Threads=n nanos=n iters=n"); |
58 |
> |
throw new Error("Usage: FutileTimedTryLockLoops minThreads=n maxThreads=n threads=n nanos=n iters=n"); |
59 |
|
} |
60 |
|
final ExecutorService pool = Executors.newCachedThreadPool(); |
61 |
|
final ReentrantLock lock = new ReentrantLock(); |
63 |
|
lock.lock(); |
64 |
|
|
65 |
|
for (int i = minThreads; i <= maxThreads; i += (i+1) >>> 1) { |
66 |
+ |
// warmup |
67 |
+ |
if (i == minThreads) |
68 |
+ |
pool.invokeAll(Collections.nCopies(i, task)); |
69 |
+ |
|
70 |
|
long startTime = System.nanoTime(); |
71 |
|
pool.invokeAll(Collections.nCopies(i, task)); |
72 |
|
long elapsed = System.nanoTime() - startTime; |