624 |
|
public void testPollInExecutor() { |
625 |
|
final PriorityBlockingQueue q = new PriorityBlockingQueue(2); |
626 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
627 |
< |
ExecutorService executor = Executors.newFixedThreadPool(2); |
628 |
< |
executor.execute(new CheckedRunnable() { |
629 |
< |
public void realRun() throws InterruptedException { |
630 |
< |
assertNull(q.poll()); |
631 |
< |
threadsStarted.await(); |
632 |
< |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
633 |
< |
checkEmpty(q); |
634 |
< |
}}); |
627 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
628 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
629 |
> |
executor.execute(new CheckedRunnable() { |
630 |
> |
public void realRun() throws InterruptedException { |
631 |
> |
assertNull(q.poll()); |
632 |
> |
threadsStarted.await(); |
633 |
> |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
634 |
> |
checkEmpty(q); |
635 |
> |
}}); |
636 |
|
|
637 |
< |
executor.execute(new CheckedRunnable() { |
638 |
< |
public void realRun() throws InterruptedException { |
639 |
< |
threadsStarted.await(); |
640 |
< |
q.put(one); |
641 |
< |
}}); |
642 |
< |
|
642 |
< |
joinPool(executor); |
637 |
> |
executor.execute(new CheckedRunnable() { |
638 |
> |
public void realRun() throws InterruptedException { |
639 |
> |
threadsStarted.await(); |
640 |
> |
q.put(one); |
641 |
> |
}}); |
642 |
> |
} |
643 |
|
} |
644 |
|
|
645 |
|
/** |