author | dl |
Mon, 30 Jan 2012 11:44:45 +0000 | |
changeset 11689 | ffbfda5c3886 |
child 14856 | 92a1bcf46888 |
permissions | -rw-r--r-- |
11689
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
1 |
/* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
2 |
* Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
4 |
* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
8 |
* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
13 |
* accompanied this code). |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
14 |
* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
18 |
* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
21 |
* questions. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
22 |
*/ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
23 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
24 |
/* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
25 |
* Written by Martin Buchholz with assistance from members of JCP JSR-166 |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
26 |
* Expert Group and released to the public domain, as explained at |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
27 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
28 |
*/ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
29 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
30 |
/* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
31 |
* @test |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
32 |
* @run main DoneTimedGetLoops 300 |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
33 |
* @summary isDone returning true guarantees that subsequent timed get |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
34 |
* will never throw TimeoutException. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
35 |
*/ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
36 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
37 |
import java.util.*; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
38 |
import java.util.concurrent.*; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
39 |
import java.util.concurrent.atomic.*; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
40 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
41 |
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
42 |
public class DoneTimedGetLoops { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
43 |
final long testDurationMillisDefault = 10L * 1000L; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
44 |
final long testDurationMillis; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
45 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
46 |
static class PublicFutureTask extends FutureTask<Boolean> { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
47 |
final static Runnable noop = new Runnable() { public void run() {} }; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
48 |
PublicFutureTask() { super(noop, null); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
49 |
public void set(Boolean v) { super.set(v); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
50 |
public void setException(Throwable t) { super.setException(t); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
51 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
52 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
53 |
DoneTimedGetLoops(String[] args) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
54 |
testDurationMillis = (args.length > 0) ? |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
55 |
Long.valueOf(args[0]) : testDurationMillisDefault; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
56 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
57 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
58 |
void test(String[] args) throws Throwable { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
59 |
final long testDurationNanos = testDurationMillis * 1000L * 1000L; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
60 |
final long quittingTimeNanos = System.nanoTime() + testDurationNanos; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
61 |
final long timeoutMillis = 10L * 1000L; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
62 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
63 |
final AtomicReference<PublicFutureTask> normalRef |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
64 |
= new AtomicReference<PublicFutureTask>(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
65 |
final AtomicReference<PublicFutureTask> abnormalRef |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
66 |
= new AtomicReference<PublicFutureTask>(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
67 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
68 |
final Throwable throwable = new Throwable(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
69 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
70 |
abstract class CheckedThread extends Thread { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
71 |
CheckedThread(String name) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
72 |
super(name); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
73 |
setDaemon(true); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
74 |
start(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
75 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
76 |
/** Polls for quitting time. */ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
77 |
protected boolean quittingTime() { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
78 |
return System.nanoTime() - quittingTimeNanos > 0; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
79 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
80 |
/** Polls occasionally for quitting time. */ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
81 |
protected boolean quittingTime(long i) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
82 |
return (i % 1024) == 0 && quittingTime(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
83 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
84 |
abstract protected void realRun() throws Exception; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
85 |
public void run() { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
86 |
try { realRun(); } catch (Throwable t) { unexpected(t); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
87 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
88 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
89 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
90 |
Thread setter = new CheckedThread("setter") { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
91 |
protected void realRun() { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
92 |
while (! quittingTime()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
93 |
PublicFutureTask future = new PublicFutureTask(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
94 |
normalRef.set(future); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
95 |
future.set(Boolean.TRUE); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
96 |
}}}; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
97 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
98 |
Thread setterException = new CheckedThread("setterException") { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
99 |
protected void realRun() { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
100 |
while (! quittingTime()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
101 |
PublicFutureTask future = new PublicFutureTask(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
102 |
abnormalRef.set(future); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
103 |
future.setException(throwable); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
104 |
}}}; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
105 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
106 |
Thread doneTimedGetNormal = new CheckedThread("doneTimedGetNormal") { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
107 |
protected void realRun() throws Exception { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
108 |
while (! quittingTime()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
109 |
PublicFutureTask future = normalRef.get(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
110 |
if (future != null) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
111 |
while (!future.isDone()) |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
112 |
; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
113 |
check(future.get(0L, TimeUnit.HOURS) == Boolean.TRUE); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
114 |
}}}}; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
115 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
116 |
Thread doneTimedGetAbnormal = new CheckedThread("doneTimedGetAbnormal") { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
117 |
protected void realRun() throws Exception { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
118 |
while (! quittingTime()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
119 |
PublicFutureTask future = abnormalRef.get(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
120 |
if (future != null) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
121 |
while (!future.isDone()) |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
122 |
; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
123 |
try { future.get(0L, TimeUnit.HOURS); fail(); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
124 |
catch (ExecutionException t) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
125 |
check(t.getCause() == throwable); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
126 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
127 |
}}}}; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
128 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
129 |
for (Thread thread : new Thread[] { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
130 |
setter, |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
131 |
setterException, |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
132 |
doneTimedGetNormal, |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
133 |
doneTimedGetAbnormal }) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
134 |
thread.join(timeoutMillis + testDurationMillis); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
135 |
if (thread.isAlive()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
136 |
System.err.printf("Hung thread: %s%n", thread.getName()); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
137 |
failed++; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
138 |
for (StackTraceElement e : thread.getStackTrace()) |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
139 |
System.err.println(e); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
140 |
// Kludge alert |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
141 |
thread.stop(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
142 |
thread.join(timeoutMillis); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
143 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
144 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
145 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
146 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
147 |
//--------------------- Infrastructure --------------------------- |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
148 |
volatile int passed = 0, failed = 0; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
149 |
void pass() {passed++;} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
150 |
void fail() {failed++; Thread.dumpStack();} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
151 |
void fail(String msg) {System.err.println(msg); fail();} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
152 |
void unexpected(Throwable t) {failed++; t.printStackTrace();} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
153 |
void check(boolean cond) {if (cond) pass(); else fail();} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
154 |
void equal(Object x, Object y) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
155 |
if (x == null ? y == null : x.equals(y)) pass(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
156 |
else fail(x + " not equal to " + y);} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
157 |
public static void main(String[] args) throws Throwable { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
158 |
new DoneTimedGetLoops(args).instanceMain(args);} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
159 |
public void instanceMain(String[] args) throws Throwable { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
160 |
try {test(args);} catch (Throwable t) {unexpected(t);} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
161 |
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
162 |
if (failed > 0) throw new AssertionError("Some tests failed");} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
163 |
} |