author | dl |
Wed, 25 Nov 2015 18:56:44 -0800 | |
changeset 34347 | 4a17f9e90a0f |
parent 32991 | b27c76b82713 |
child 43522 | f9c6f543c4db |
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 |
* 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
|
3 |
* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
4 |
* 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
|
5 |
* 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
|
6 |
* published by the Free Software Foundation. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
7 |
* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
8 |
* 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
|
9 |
* 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
|
10 |
* 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
|
11 |
* 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
|
12 |
* accompanied this code). |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
13 |
* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
14 |
* 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
|
15 |
* 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
|
16 |
* 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
|
17 |
* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
18 |
* 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
|
19 |
* 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
|
20 |
* questions. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
21 |
*/ |
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 |
/* |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
32649
diff
changeset
|
24 |
* This file is available under and governed by the GNU General Public |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
32649
diff
changeset
|
25 |
* License version 2 only, as published by the Free Software Foundation. |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
32649
diff
changeset
|
26 |
* However, the following notice accompanied the original version of this |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
32649
diff
changeset
|
27 |
* file: |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
32649
diff
changeset
|
28 |
* |
11689
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
29 |
* 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
|
30 |
* 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
|
31 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
32 |
*/ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
33 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
34 |
/* |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
35 |
* @test |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
36 |
* @run main DoneTimedGetLoops 300 |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
37 |
* @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
|
38 |
* will never throw TimeoutException. |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
39 |
*/ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
40 |
|
34347 | 41 |
import java.util.concurrent.ExecutionException; |
42 |
import java.util.concurrent.FutureTask; |
|
43 |
import java.util.concurrent.TimeUnit; |
|
44 |
import java.util.concurrent.atomic.AtomicReference; |
|
11689
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 |
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
47 |
public class DoneTimedGetLoops { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
48 |
final long testDurationMillisDefault = 10L * 1000L; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
49 |
final long testDurationMillis; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
50 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
51 |
static class PublicFutureTask extends FutureTask<Boolean> { |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
14856
diff
changeset
|
52 |
static final Runnable noop = new Runnable() { public void run() {} }; |
11689
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
53 |
PublicFutureTask() { super(noop, null); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
54 |
public void set(Boolean v) { super.set(v); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
55 |
public void setException(Throwable t) { super.setException(t); } |
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 |
DoneTimedGetLoops(String[] args) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
59 |
testDurationMillis = (args.length > 0) ? |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
60 |
Long.valueOf(args[0]) : testDurationMillisDefault; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
61 |
} |
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 |
void test(String[] args) throws Throwable { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
64 |
final long testDurationNanos = testDurationMillis * 1000L * 1000L; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
65 |
final long quittingTimeNanos = System.nanoTime() + testDurationNanos; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
66 |
final long timeoutMillis = 10L * 1000L; |
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 AtomicReference<PublicFutureTask> normalRef |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
69 |
= new AtomicReference<PublicFutureTask>(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
70 |
final AtomicReference<PublicFutureTask> abnormalRef |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
71 |
= new AtomicReference<PublicFutureTask>(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
72 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
73 |
final Throwable throwable = new Throwable(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
74 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
75 |
abstract class CheckedThread extends Thread { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
76 |
CheckedThread(String name) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
77 |
super(name); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
78 |
setDaemon(true); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
79 |
start(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
80 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
81 |
/** Polls for quitting time. */ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
82 |
protected boolean quittingTime() { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
83 |
return System.nanoTime() - quittingTimeNanos > 0; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
84 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
85 |
/** Polls occasionally for quitting time. */ |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
86 |
protected boolean quittingTime(long i) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
87 |
return (i % 1024) == 0 && quittingTime(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
88 |
} |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
14856
diff
changeset
|
89 |
protected abstract void realRun() throws Exception; |
11689
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
90 |
public void run() { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
91 |
try { realRun(); } catch (Throwable t) { unexpected(t); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
92 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
93 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
94 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
95 |
Thread setter = new CheckedThread("setter") { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
96 |
protected void realRun() { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
97 |
while (! quittingTime()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
98 |
PublicFutureTask future = new PublicFutureTask(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
99 |
normalRef.set(future); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
100 |
future.set(Boolean.TRUE); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
101 |
}}}; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
102 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
103 |
Thread setterException = new CheckedThread("setterException") { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
104 |
protected void realRun() { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
105 |
while (! quittingTime()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
106 |
PublicFutureTask future = new PublicFutureTask(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
107 |
abnormalRef.set(future); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
108 |
future.setException(throwable); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
109 |
}}}; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
110 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
111 |
Thread doneTimedGetNormal = new CheckedThread("doneTimedGetNormal") { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
112 |
protected void realRun() throws Exception { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
113 |
while (! quittingTime()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
114 |
PublicFutureTask future = normalRef.get(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
115 |
if (future != null) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
116 |
while (!future.isDone()) |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
117 |
; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
118 |
check(future.get(0L, TimeUnit.HOURS) == Boolean.TRUE); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
119 |
}}}}; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
120 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
121 |
Thread doneTimedGetAbnormal = new CheckedThread("doneTimedGetAbnormal") { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
122 |
protected void realRun() throws Exception { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
123 |
while (! quittingTime()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
124 |
PublicFutureTask future = abnormalRef.get(); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
125 |
if (future != null) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
126 |
while (!future.isDone()) |
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 |
try { future.get(0L, TimeUnit.HOURS); fail(); } |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
129 |
catch (ExecutionException t) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
130 |
check(t.getCause() == throwable); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
131 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
132 |
}}}}; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
133 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
134 |
for (Thread thread : new Thread[] { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
135 |
setter, |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
136 |
setterException, |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
137 |
doneTimedGetNormal, |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
138 |
doneTimedGetAbnormal }) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
139 |
thread.join(timeoutMillis + testDurationMillis); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
140 |
if (thread.isAlive()) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
141 |
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
|
142 |
failed++; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
143 |
for (StackTraceElement e : thread.getStackTrace()) |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
144 |
System.err.println(e); |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
145 |
thread.join(timeoutMillis); |
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 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
148 |
} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
149 |
|
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
150 |
//--------------------- Infrastructure --------------------------- |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
151 |
volatile int passed = 0, failed = 0; |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
152 |
void pass() {passed++;} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
153 |
void fail() {failed++; Thread.dumpStack();} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
154 |
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
|
155 |
void unexpected(Throwable t) {failed++; t.printStackTrace();} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
156 |
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
|
157 |
void equal(Object x, Object y) { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
158 |
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
|
159 |
else fail(x + " not equal to " + y);} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
160 |
public static void main(String[] args) throws Throwable { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
161 |
new DoneTimedGetLoops(args).instanceMain(args);} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
162 |
public void instanceMain(String[] args) throws Throwable { |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
163 |
try {test(args);} catch (Throwable t) {unexpected(t);} |
ffbfda5c3886
7132378: Race in FutureTask if used with explicit set ( not Runnable )
dl
parents:
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
} |