18 |
|
import java.util.concurrent.Executors; |
19 |
|
import java.util.concurrent.ExecutorService; |
20 |
|
import java.util.concurrent.SynchronousQueue; |
21 |
– |
import java.util.concurrent.ThreadLocalRandom; |
21 |
|
|
22 |
|
import junit.framework.Test; |
23 |
|
|
189 |
|
* timed offer times out if elements not taken |
190 |
|
*/ |
191 |
|
public void testTimedOffer() { |
192 |
< |
final boolean fair = ThreadLocalRandom.current().nextBoolean(); |
192 |
> |
final boolean fair = randomBoolean(); |
193 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
194 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
195 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
247 |
|
* timed poll with nonzero timeout times out if no active putter |
248 |
|
*/ |
249 |
|
public void testTimedPoll() { |
250 |
< |
final boolean fair = ThreadLocalRandom.current().nextBoolean(); |
250 |
> |
final boolean fair = randomBoolean(); |
251 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
252 |
|
final long startTime = System.nanoTime(); |
253 |
|
try { assertNull(q.poll(timeoutMillis(), MILLISECONDS)); } |
260 |
|
* after offer succeeds; on interruption throws |
261 |
|
*/ |
262 |
|
public void testTimedPollWithOffer() { |
263 |
< |
final boolean fair = ThreadLocalRandom.current().nextBoolean(); |
263 |
> |
final boolean fair = randomBoolean(); |
264 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
265 |
|
final CountDownLatch pleaseOffer = new CountDownLatch(1); |
266 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |