1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
159 |
|
q.put(null); |
160 |
|
shouldThrow(); |
161 |
|
} catch (NullPointerException success) {} |
162 |
< |
} |
162 |
> |
} |
163 |
|
|
164 |
|
/** |
165 |
|
* put blocks interruptibly if no active taker |
172 |
|
}}); |
173 |
|
|
174 |
|
t.start(); |
175 |
< |
Thread.sleep(SHORT_DELAY_MS); |
175 |
> |
delay(SHORT_DELAY_MS); |
176 |
|
t.interrupt(); |
177 |
|
t.join(); |
178 |
|
} |
196 |
|
}}); |
197 |
|
|
198 |
|
t.start(); |
199 |
< |
Thread.sleep(SHORT_DELAY_MS); |
199 |
> |
delay(SHORT_DELAY_MS); |
200 |
|
assertEquals(0, q.take()); |
201 |
< |
Thread.sleep(SHORT_DELAY_MS); |
201 |
> |
delay(SHORT_DELAY_MS); |
202 |
|
t.interrupt(); |
203 |
|
t.join(); |
204 |
|
} |
211 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
212 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
213 |
|
public void realRun() throws InterruptedException { |
214 |
< |
long t0 = System.nanoTime(); |
215 |
< |
assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
216 |
< |
assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS); |
214 |
> |
long startTime = System.nanoTime(); |
215 |
> |
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); |
216 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
217 |
|
pleaseInterrupt.countDown(); |
218 |
– |
t0 = System.nanoTime(); |
218 |
|
try { |
219 |
< |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
219 |
> |
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
220 |
|
shouldThrow(); |
221 |
|
} catch (InterruptedException success) {} |
223 |
– |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
222 |
|
}}); |
223 |
|
|
224 |
< |
assertTrue(pleaseInterrupt.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
224 |
> |
await(pleaseInterrupt); |
225 |
|
t.interrupt(); |
226 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
226 |
> |
awaitTermination(t); |
227 |
|
} |
228 |
|
|
229 |
|
/** |
251 |
|
}}); |
252 |
|
|
253 |
|
t.start(); |
254 |
< |
Thread.sleep(SHORT_DELAY_MS); |
254 |
> |
delay(SHORT_DELAY_MS); |
255 |
|
t.interrupt(); |
256 |
|
t.join(); |
257 |
|
} |
275 |
|
}}); |
276 |
|
|
277 |
|
t.start(); |
278 |
< |
Thread.sleep(SHORT_DELAY_MS); |
278 |
> |
delay(SHORT_DELAY_MS); |
279 |
|
assertEquals(0, q.take()); |
280 |
< |
Thread.sleep(SHORT_DELAY_MS); |
280 |
> |
delay(SHORT_DELAY_MS); |
281 |
|
t.interrupt(); |
282 |
|
t.join(); |
283 |
|
} |
293 |
|
}}); |
294 |
|
|
295 |
|
t.start(); |
296 |
< |
Thread.sleep(SHORT_DELAY_MS); |
296 |
> |
delay(SHORT_DELAY_MS); |
297 |
|
t.interrupt(); |
298 |
|
t.join(); |
299 |
|
} |
344 |
|
}}); |
345 |
|
|
346 |
|
threadStarted.await(); |
347 |
< |
Thread.sleep(SHORT_DELAY_MS); |
347 |
> |
delay(SHORT_DELAY_MS); |
348 |
|
t.interrupt(); |
349 |
|
awaitTermination(t, MEDIUM_DELAY_MS); |
350 |
|
} |
571 |
|
|
572 |
|
executor.execute(new CheckedRunnable() { |
573 |
|
public void realRun() throws InterruptedException { |
574 |
< |
Thread.sleep(SMALL_DELAY_MS); |
574 |
> |
delay(SMALL_DELAY_MS); |
575 |
|
assertSame(one, q.take()); |
576 |
|
}}); |
577 |
|
|
593 |
|
|
594 |
|
executor.execute(new CheckedRunnable() { |
595 |
|
public void realRun() throws InterruptedException { |
596 |
< |
Thread.sleep(SHORT_DELAY_MS); |
596 |
> |
delay(SHORT_DELAY_MS); |
597 |
|
q.put(one); |
598 |
|
}}); |
599 |
|
|
663 |
|
|
664 |
|
t.start(); |
665 |
|
ArrayList l = new ArrayList(); |
666 |
< |
Thread.sleep(SHORT_DELAY_MS); |
666 |
> |
delay(SHORT_DELAY_MS); |
667 |
|
q.drainTo(l); |
668 |
|
assertTrue(l.size() <= 1); |
669 |
|
if (l.size() > 0) |
712 |
|
t1.start(); |
713 |
|
t2.start(); |
714 |
|
ArrayList l = new ArrayList(); |
715 |
< |
Thread.sleep(SHORT_DELAY_MS); |
715 |
> |
delay(SHORT_DELAY_MS); |
716 |
|
q.drainTo(l, 1); |
717 |
|
assertEquals(1, l.size()); |
718 |
|
q.drainTo(l, 1); |