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 |
< |
import java.util.concurrent.*; |
8 |
< |
import java.util.concurrent.locks.*; |
9 |
< |
import java.util.*; |
7 |
> |
import java.util.Arrays; |
8 |
> |
import java.util.Collections; |
9 |
> |
import java.util.Random; |
10 |
> |
import java.util.concurrent.BrokenBarrierException; |
11 |
> |
import java.util.concurrent.CyclicBarrier; |
12 |
> |
import java.util.concurrent.locks.ReentrantLock; |
13 |
|
|
14 |
|
public final class CancelledLockLoops { |
15 |
|
static final Random rng = new Random(); |
54 |
|
threads[i] = new Thread(this); |
55 |
|
for (int i = 0; i < threads.length; ++i) |
56 |
|
threads[i].start(); |
57 |
< |
Thread[] cancels = (Thread[]) (threads.clone()); |
57 |
> |
Thread[] cancels = threads.clone(); |
58 |
|
Collections.shuffle(Arrays.asList(cancels), rng); |
59 |
|
barrier.await(); |
60 |
|
Thread.sleep(TIMEOUT); |
67 |
|
barrier.await(); |
68 |
|
if (print) { |
69 |
|
long time = timer.getTime(); |
70 |
< |
double secs = (double)(time) / 1000000000.0; |
70 |
> |
double secs = (double) time / 1000000000.0; |
71 |
|
System.out.println("\t " + secs + "s run time"); |
72 |
|
} |
73 |
|
|