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