62 |
|
PriorityBlockingQueue<Integer> q = |
63 |
|
new PriorityBlockingQueue<Integer>(n); |
64 |
|
assertTrue(q.isEmpty()); |
65 |
< |
for (int i = n-1; i >= 0; i -= 2) |
65 |
> |
for (int i = n - 1; i >= 0; i -= 2) |
66 |
|
assertTrue(q.offer(new Integer(i))); |
67 |
|
for (int i = (n & 1); i < n; i += 2) |
68 |
|
assertTrue(q.offer(new Integer(i))); |
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 |
< |
}}); |
635 |
< |
|
636 |
< |
executor.execute(new CheckedRunnable() { |
637 |
< |
public void realRun() throws InterruptedException { |
638 |
< |
threadsStarted.await(); |
639 |
< |
q.put(one); |
640 |
< |
}}); |
641 |
< |
|
642 |
< |
joinPool(executor); |
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 |
> |
} |
643 |
|
} |
644 |
|
|
645 |
|
/** |