74 |
|
} |
75 |
|
|
76 |
|
private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { |
77 |
< |
try { |
77 |
> |
try (PoolCleaner cleaner = cleaner(pool)) { |
78 |
|
assertFalse(a.isDone()); |
79 |
|
assertFalse(a.isCompletedNormally()); |
80 |
|
assertFalse(a.isCompletedAbnormally()); |
90 |
|
assertFalse(a.isCancelled()); |
91 |
|
assertNull(a.getException()); |
92 |
|
assertNull(a.getRawResult()); |
93 |
– |
} finally { |
94 |
– |
joinPool(pool); |
93 |
|
} |
94 |
|
} |
95 |
|
|
126 |
|
|
127 |
|
{ |
128 |
|
Thread.currentThread().interrupt(); |
129 |
< |
long t0 = System.nanoTime(); |
129 |
> |
long startTime = System.nanoTime(); |
130 |
|
assertSame(expected, a.join()); |
131 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
131 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
132 |
|
Thread.interrupted(); |
133 |
|
} |
134 |
|
|
135 |
|
{ |
136 |
|
Thread.currentThread().interrupt(); |
137 |
< |
long t0 = System.nanoTime(); |
137 |
> |
long startTime = System.nanoTime(); |
138 |
|
a.quietlyJoin(); // should be no-op |
139 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
139 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
140 |
|
Thread.interrupted(); |
141 |
|
} |
142 |
|
|
172 |
|
Thread.interrupted(); |
173 |
|
|
174 |
|
{ |
175 |
< |
long t0 = System.nanoTime(); |
175 |
> |
long startTime = System.nanoTime(); |
176 |
|
a.quietlyJoin(); // should be no-op |
177 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
177 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
178 |
|
} |
179 |
|
|
180 |
|
try { |
198 |
|
|
199 |
|
abstract static class BinaryAsyncAction extends ForkJoinTask<Void> { |
200 |
|
|
201 |
< |
private BinaryAsyncAction parent; |
201 |
> |
private volatile BinaryAsyncAction parent; |
202 |
|
|
203 |
< |
private BinaryAsyncAction sibling; |
203 |
> |
private volatile BinaryAsyncAction sibling; |
204 |
|
|
205 |
|
protected BinaryAsyncAction() { |
206 |
|
setForkJoinTaskTag(INITIAL_STATE); |
317 |
|
} |
318 |
|
catch (Throwable ex) { |
319 |
|
compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE); |
320 |
+ |
throw new Error(ex); |
321 |
|
} |
322 |
|
return false; |
323 |
|
} |
1154 |
|
} |
1155 |
|
|
1156 |
|
// jdk9 |
1157 |
< |
|
1157 |
> |
|
1158 |
|
/** |
1159 |
|
* pollSubmission returns unexecuted submitted task, if present |
1160 |
|
*/ |
1164 |
|
final ForkJoinTask b = ForkJoinTask.adapt(awaiter(done)); |
1165 |
|
final ForkJoinTask c = ForkJoinTask.adapt(awaiter(done)); |
1166 |
|
final ForkJoinPool p = singletonPool(); |
1167 |
< |
Thread external = new Thread() { |
1168 |
< |
public void run() { |
1167 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
1168 |
> |
Thread external = new Thread(new CheckedRunnable() { |
1169 |
> |
public void realRun() { |
1170 |
|
p.execute(a); |
1171 |
|
p.execute(b); |
1172 |
|
p.execute(c); |
1173 |
< |
}}; |
1174 |
< |
RecursiveAction s = new CheckedRecursiveAction() { |
1173 |
> |
}}); |
1174 |
> |
RecursiveAction s = new CheckedRecursiveAction() { |
1175 |
|
protected void realCompute() { |
1176 |
|
external.start(); |
1177 |
|
try { |
1178 |
|
external.join(); |
1179 |
< |
} catch(Exception ex) { |
1179 |
> |
} catch (Exception ex) { |
1180 |
|
threadUnexpectedException(ex); |
1181 |
|
} |
1182 |
|
assertTrue(p.hasQueuedSubmissions()); |
1185 |
|
assertTrue(r == a || r == b || r == c); |
1186 |
|
assertFalse(r.isDone()); |
1187 |
|
}}; |
1188 |
– |
try { |
1188 |
|
p.invoke(s); |
1190 |
– |
} finally { |
1191 |
– |
done.countDown(); |
1192 |
– |
joinPool(p); |
1189 |
|
} |
1190 |
|
} |
1191 |
|
|
1196 |
– |
|
1192 |
|
} |