124 |
|
private DelayQueue<PDelay> populatedQueue(int n) { |
125 |
|
DelayQueue<PDelay> q = new DelayQueue<PDelay>(); |
126 |
|
assertTrue(q.isEmpty()); |
127 |
< |
for (int i = n-1; i >= 0; i -= 2) |
127 |
> |
for (int i = n - 1; i >= 0; i -= 2) |
128 |
|
assertTrue(q.offer(new PDelay(i))); |
129 |
|
for (int i = (n & 1); i < n; i += 2) |
130 |
|
assertTrue(q.offer(new PDelay(i))); |
653 |
|
public void testPollInExecutor() { |
654 |
|
final DelayQueue q = new DelayQueue(); |
655 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
656 |
< |
ExecutorService executor = Executors.newFixedThreadPool(2); |
657 |
< |
executor.execute(new CheckedRunnable() { |
658 |
< |
public void realRun() throws InterruptedException { |
659 |
< |
assertNull(q.poll()); |
660 |
< |
threadsStarted.await(); |
661 |
< |
assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS)); |
662 |
< |
checkEmpty(q); |
663 |
< |
}}); |
664 |
< |
|
665 |
< |
executor.execute(new CheckedRunnable() { |
666 |
< |
public void realRun() throws InterruptedException { |
667 |
< |
threadsStarted.await(); |
668 |
< |
q.put(new PDelay(1)); |
669 |
< |
}}); |
670 |
< |
|
671 |
< |
joinPool(executor); |
656 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
657 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
658 |
> |
executor.execute(new CheckedRunnable() { |
659 |
> |
public void realRun() throws InterruptedException { |
660 |
> |
assertNull(q.poll()); |
661 |
> |
threadsStarted.await(); |
662 |
> |
assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS)); |
663 |
> |
checkEmpty(q); |
664 |
> |
}}); |
665 |
> |
|
666 |
> |
executor.execute(new CheckedRunnable() { |
667 |
> |
public void realRun() throws InterruptedException { |
668 |
> |
threadsStarted.await(); |
669 |
> |
q.put(new PDelay(1)); |
670 |
> |
}}); |
671 |
> |
} |
672 |
|
} |
673 |
|
|
674 |
|
/** |