156 |
|
public void realRun() { |
157 |
|
assertFalse(Thread.currentThread().isInterrupted()); |
158 |
|
threadStarted.countDown(); |
159 |
< |
LockSupport.park(); |
160 |
< |
assertTrue(Thread.currentThread().isInterrupted()); |
159 |
> |
do { |
160 |
> |
LockSupport.park(); |
161 |
> |
// park may return spuriously |
162 |
> |
} while (! Thread.currentThread().isInterrupted()); |
163 |
|
}}); |
164 |
|
|
165 |
|
threadStarted.await(); |
178 |
|
long d = new Date().getTime() + LONG_DELAY_MS; |
179 |
|
long nanos = LONG_DELAY_MS * 1000L * 1000L; |
180 |
|
long t0 = System.nanoTime(); |
181 |
+ |
assertFalse(Thread.currentThread().isInterrupted()); |
182 |
|
threadStarted.countDown(); |
183 |
< |
LockSupport.parkUntil(d); |
183 |
> |
do { |
184 |
> |
LockSupport.parkUntil(d); |
185 |
> |
// parkUntil may return spuriously |
186 |
> |
} while (! Thread.currentThread().isInterrupted()); |
187 |
|
assertTrue(System.nanoTime() - t0 < nanos); |
188 |
|
}}); |
189 |
|
|
202 |
|
public void realRun() { |
203 |
|
long nanos = LONG_DELAY_MS * 1000L * 1000L; |
204 |
|
long t0 = System.nanoTime(); |
205 |
+ |
assertFalse(Thread.currentThread().isInterrupted()); |
206 |
|
threadStarted.countDown(); |
207 |
< |
LockSupport.parkNanos(nanos); |
207 |
> |
do { |
208 |
> |
LockSupport.parkNanos(nanos); |
209 |
> |
// parkNanos may return spuriously |
210 |
> |
} while (! Thread.currentThread().isInterrupted()); |
211 |
|
assertTrue(System.nanoTime() - t0 < nanos); |
212 |
|
}}); |
213 |
|
|
253 |
|
long d = new Date().getTime() + LONG_DELAY_MS; |
254 |
|
long nanos = LONG_DELAY_MS * 1000L * 1000L; |
255 |
|
long t0 = System.nanoTime(); |
256 |
+ |
assertTrue(Thread.currentThread().isInterrupted()); |
257 |
|
LockSupport.parkUntil(d); |
258 |
|
assertTrue(System.nanoTime() - t0 < nanos); |
259 |
+ |
assertTrue(Thread.currentThread().isInterrupted()); |
260 |
|
}}); |
261 |
|
|
262 |
|
threadStarted.await(); |
278 |
|
Thread.yield(); |
279 |
|
long nanos = LONG_DELAY_MS * 1000L * 1000L; |
280 |
|
long t0 = System.nanoTime(); |
281 |
+ |
assertTrue(Thread.currentThread().isInterrupted()); |
282 |
|
LockSupport.parkNanos(nanos); |
283 |
|
assertTrue(System.nanoTime() - t0 < nanos); |
284 |
+ |
assertTrue(Thread.currentThread().isInterrupted()); |
285 |
|
}}); |
286 |
|
|
287 |
|
threadStarted.await(); |
296 |
|
public void testParkNanosTimesOut() throws InterruptedException { |
297 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
298 |
|
public void realRun() { |
299 |
< |
final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L; |
300 |
< |
long t0 = System.nanoTime(); |
301 |
< |
LockSupport.parkNanos(timeoutNanos); |
302 |
< |
assertTrue(System.nanoTime() - t0 >= timeoutNanos); |
299 |
> |
for (;;) { |
300 |
> |
long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L; |
301 |
> |
long t0 = System.nanoTime(); |
302 |
> |
LockSupport.parkNanos(timeoutNanos); |
303 |
> |
// parkNanos may return spuriously |
304 |
> |
if (System.nanoTime() - t0 >= timeoutNanos) |
305 |
> |
return; |
306 |
> |
} |
307 |
|
}}); |
308 |
|
|
309 |
|
awaitTermination(t, MEDIUM_DELAY_MS); |
316 |
|
public void testParkUntilTimesOut() throws InterruptedException { |
317 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
318 |
|
public void realRun() { |
319 |
< |
long d = new Date().getTime() + SHORT_DELAY_MS; |
320 |
< |
// beware of rounding |
321 |
< |
long timeoutNanos = (SHORT_DELAY_MS - 1) * 1000L * 1000L; |
322 |
< |
long t0 = System.nanoTime(); |
323 |
< |
LockSupport.parkUntil(d); |
324 |
< |
assertTrue(System.nanoTime() - t0 >= timeoutNanos); |
319 |
> |
for (;;) { |
320 |
> |
long d = new Date().getTime() + SHORT_DELAY_MS; |
321 |
> |
// beware of rounding |
322 |
> |
long timeoutNanos = (SHORT_DELAY_MS - 1) * 1000L * 1000L; |
323 |
> |
long t0 = System.nanoTime(); |
324 |
> |
LockSupport.parkUntil(d); |
325 |
> |
// parkUntil may return spuriously |
326 |
> |
if (System.nanoTime() - t0 >= timeoutNanos) |
327 |
> |
return; |
328 |
> |
} |
329 |
|
}}); |
330 |
|
|
331 |
|
awaitTermination(t, MEDIUM_DELAY_MS); |