6 |
|
|
7 |
|
/* |
8 |
|
* @test |
9 |
< |
* @summary Checks for responsiveness of futures to cancellation. |
9 |
> |
* @summary Checks for responsiveness of futures to cancellation. |
10 |
|
* Runs under |
11 |
|
* the assumption that ITERS computations require more than TIMEOUT |
12 |
|
* msecs to complete. |
27 |
|
static final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom(); |
28 |
|
static boolean print = false; |
29 |
|
static final int ITERS = 10000000; |
30 |
< |
static final long TIMEOUT = 100; |
30 |
> |
static final long TIMEOUT = 100; |
31 |
|
|
32 |
|
public static void main(String[] args) throws Exception { |
33 |
|
int maxThreads = 100; |
34 |
< |
if (args.length > 0) |
34 |
> |
if (args.length > 0) |
35 |
|
maxThreads = Integer.parseInt(args[0]); |
36 |
|
|
37 |
|
print = true; |
57 |
|
|
58 |
|
final void test() throws Exception { |
59 |
|
Future[] futures = new Future[nthreads]; |
60 |
< |
for (int i = 0; i < nthreads; ++i) |
60 |
> |
for (int i = 0; i < nthreads; ++i) |
61 |
|
futures[i] = pool.submit(this); |
62 |
|
|
63 |
|
barrier.await(); |
67 |
|
if (!futures[i].cancel(true)) |
68 |
|
tooLate = true; |
69 |
|
// Unbunch some of the cancels |
70 |
< |
if ( (i & 3) == 0) |
70 |
> |
if ( (i & 3) == 0) |
71 |
|
Thread.sleep(1 + rng.next() % 10); |
72 |
|
} |
73 |
|
|
80 |
|
} |
81 |
|
else |
82 |
|
System.out.print("(cancelled too late) "); |
83 |
< |
|
83 |
> |
|
84 |
|
long endTime = System.nanoTime(); |
85 |
|
long time = endTime - timer.startTime; |
86 |
|
if (print) { |
91 |
|
} |
92 |
|
|
93 |
|
public final Object call() throws Exception { |
94 |
< |
barrier.await(); |
94 |
> |
barrier.await(); |
95 |
|
int sum = v; |
96 |
|
int x = 0; |
97 |
|
int n = ITERS; |
104 |
|
lock.unlock(); |
105 |
|
} |
106 |
|
sum += LoopHelpers.compute2(LoopHelpers.compute2(x)); |
107 |
< |
} |
107 |
> |
} |
108 |
|
return new Integer(sum); |
109 |
|
} |
110 |
|
} |