469 |
|
public void testOfferInExecutor_fair() { testOfferInExecutor(true); } |
470 |
|
public void testOfferInExecutor(boolean fair) { |
471 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
472 |
– |
ExecutorService executor = Executors.newFixedThreadPool(2); |
472 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
473 |
+ |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
474 |
+ |
try (PoolCleaner cleaner = cleaner(executor)) { |
475 |
|
|
476 |
< |
executor.execute(new CheckedRunnable() { |
477 |
< |
public void realRun() throws InterruptedException { |
478 |
< |
assertFalse(q.offer(one)); |
479 |
< |
threadsStarted.await(); |
480 |
< |
assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS)); |
481 |
< |
assertEquals(0, q.remainingCapacity()); |
482 |
< |
}}); |
483 |
< |
|
484 |
< |
executor.execute(new CheckedRunnable() { |
485 |
< |
public void realRun() throws InterruptedException { |
486 |
< |
threadsStarted.await(); |
487 |
< |
assertSame(one, q.take()); |
488 |
< |
}}); |
489 |
< |
|
489 |
< |
joinPool(executor); |
476 |
> |
executor.execute(new CheckedRunnable() { |
477 |
> |
public void realRun() throws InterruptedException { |
478 |
> |
assertFalse(q.offer(one)); |
479 |
> |
threadsStarted.await(); |
480 |
> |
assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS)); |
481 |
> |
assertEquals(0, q.remainingCapacity()); |
482 |
> |
}}); |
483 |
> |
|
484 |
> |
executor.execute(new CheckedRunnable() { |
485 |
> |
public void realRun() throws InterruptedException { |
486 |
> |
threadsStarted.await(); |
487 |
> |
assertSame(one, q.take()); |
488 |
> |
}}); |
489 |
> |
} |
490 |
|
} |
491 |
|
|
492 |
|
/** |
497 |
|
public void testPollInExecutor(boolean fair) { |
498 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
499 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
500 |
< |
ExecutorService executor = Executors.newFixedThreadPool(2); |
501 |
< |
executor.execute(new CheckedRunnable() { |
502 |
< |
public void realRun() throws InterruptedException { |
503 |
< |
assertNull(q.poll()); |
504 |
< |
threadsStarted.await(); |
505 |
< |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
506 |
< |
assertTrue(q.isEmpty()); |
507 |
< |
}}); |
508 |
< |
|
509 |
< |
executor.execute(new CheckedRunnable() { |
510 |
< |
public void realRun() throws InterruptedException { |
511 |
< |
threadsStarted.await(); |
512 |
< |
q.put(one); |
513 |
< |
}}); |
514 |
< |
|
515 |
< |
joinPool(executor); |
500 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
501 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
502 |
> |
executor.execute(new CheckedRunnable() { |
503 |
> |
public void realRun() throws InterruptedException { |
504 |
> |
assertNull(q.poll()); |
505 |
> |
threadsStarted.await(); |
506 |
> |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
507 |
> |
assertTrue(q.isEmpty()); |
508 |
> |
}}); |
509 |
> |
|
510 |
> |
executor.execute(new CheckedRunnable() { |
511 |
> |
public void realRun() throws InterruptedException { |
512 |
> |
threadsStarted.await(); |
513 |
> |
q.put(one); |
514 |
> |
}}); |
515 |
> |
} |
516 |
|
} |
517 |
|
|
518 |
|
/** |