28 |
|
import java.util.concurrent.SynchronousQueue; |
29 |
|
import java.util.concurrent.ThreadFactory; |
30 |
|
import java.util.concurrent.ThreadPoolExecutor; |
31 |
– |
import java.util.concurrent.TimeUnit; |
31 |
|
import java.util.concurrent.atomic.AtomicInteger; |
32 |
|
|
33 |
|
import junit.framework.Test; |
536 |
|
*/ |
537 |
|
public void testGetQueue() throws InterruptedException { |
538 |
|
final CountDownLatch done = new CountDownLatch(1); |
539 |
< |
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10); |
539 |
> |
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10); |
540 |
|
final ThreadPoolExecutor p = |
541 |
|
new ThreadPoolExecutor(1, 1, |
542 |
|
LONG_DELAY_MS, MILLISECONDS, |
568 |
|
*/ |
569 |
|
public void testRemove() throws InterruptedException { |
570 |
|
final CountDownLatch done = new CountDownLatch(1); |
571 |
< |
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10); |
571 |
> |
BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10); |
572 |
|
final ThreadPoolExecutor p = |
573 |
|
new ThreadPoolExecutor(1, 1, |
574 |
|
LONG_DELAY_MS, MILLISECONDS, |
603 |
|
public void testPurge() throws InterruptedException { |
604 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
605 |
|
final CountDownLatch done = new CountDownLatch(1); |
606 |
< |
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10); |
606 |
> |
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10); |
607 |
|
final ThreadPoolExecutor p = |
608 |
|
new ThreadPoolExecutor(1, 1, |
609 |
|
LONG_DELAY_MS, MILLISECONDS, |
1507 |
|
LONG_DELAY_MS, MILLISECONDS, |
1508 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1509 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1510 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1510 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1511 |
|
l.add(latchAwaitingStringTask(latch)); |
1512 |
|
l.add(null); |
1513 |
|
try { |
1527 |
|
LONG_DELAY_MS, MILLISECONDS, |
1528 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1529 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1530 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1530 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1531 |
|
l.add(new NPETask()); |
1532 |
|
try { |
1533 |
|
e.invokeAny(l); |
1547 |
|
LONG_DELAY_MS, MILLISECONDS, |
1548 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1549 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1550 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1550 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1551 |
|
l.add(new StringTask()); |
1552 |
|
l.add(new StringTask()); |
1553 |
|
String result = e.invokeAny(l); |
1594 |
|
LONG_DELAY_MS, MILLISECONDS, |
1595 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1596 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1597 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1597 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1598 |
|
l.add(new StringTask()); |
1599 |
|
l.add(null); |
1600 |
|
try { |
1613 |
|
LONG_DELAY_MS, MILLISECONDS, |
1614 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1615 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1616 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1616 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1617 |
|
l.add(new NPETask()); |
1618 |
|
List<Future<String>> futures = e.invokeAll(l); |
1619 |
|
assertEquals(1, futures.size()); |
1635 |
|
LONG_DELAY_MS, MILLISECONDS, |
1636 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1637 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1638 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1638 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1639 |
|
l.add(new StringTask()); |
1640 |
|
l.add(new StringTask()); |
1641 |
|
List<Future<String>> futures = e.invokeAll(l); |
1670 |
|
LONG_DELAY_MS, MILLISECONDS, |
1671 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1672 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1673 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1673 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1674 |
|
l.add(new StringTask()); |
1675 |
|
try { |
1676 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
1706 |
|
LONG_DELAY_MS, MILLISECONDS, |
1707 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1708 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1709 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1709 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1710 |
|
l.add(latchAwaitingStringTask(latch)); |
1711 |
|
l.add(null); |
1712 |
|
try { |
1727 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1728 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1729 |
|
long startTime = System.nanoTime(); |
1730 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1730 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1731 |
|
l.add(new NPETask()); |
1732 |
|
try { |
1733 |
|
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
1749 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1750 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1751 |
|
long startTime = System.nanoTime(); |
1752 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1752 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1753 |
|
l.add(new StringTask()); |
1754 |
|
l.add(new StringTask()); |
1755 |
|
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
1783 |
|
LONG_DELAY_MS, MILLISECONDS, |
1784 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1785 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1786 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1786 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1787 |
|
l.add(new StringTask()); |
1788 |
|
try { |
1789 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1816 |
|
LONG_DELAY_MS, MILLISECONDS, |
1817 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1818 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1819 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1819 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1820 |
|
l.add(new StringTask()); |
1821 |
|
l.add(null); |
1822 |
|
try { |
1835 |
|
LONG_DELAY_MS, MILLISECONDS, |
1836 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1837 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1838 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1838 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1839 |
|
l.add(new NPETask()); |
1840 |
|
List<Future<String>> futures = |
1841 |
|
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); |
1858 |
|
LONG_DELAY_MS, MILLISECONDS, |
1859 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1860 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1861 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1861 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1862 |
|
l.add(new StringTask()); |
1863 |
|
l.add(new StringTask()); |
1864 |
|
List<Future<String>> futures = |