6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
10 |
– |
import java.util.concurrent.*; |
9 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
+ |
import static java.util.concurrent.TimeUnit.SECONDS; |
11 |
+ |
|
12 |
+ |
import java.util.ArrayList; |
13 |
+ |
import java.util.List; |
14 |
+ |
import java.util.concurrent.ArrayBlockingQueue; |
15 |
+ |
import java.util.concurrent.BlockingQueue; |
16 |
+ |
import java.util.concurrent.Callable; |
17 |
+ |
import java.util.concurrent.CancellationException; |
18 |
+ |
import java.util.concurrent.CountDownLatch; |
19 |
+ |
import java.util.concurrent.ExecutionException; |
20 |
+ |
import java.util.concurrent.Executors; |
21 |
+ |
import java.util.concurrent.ExecutorService; |
22 |
+ |
import java.util.concurrent.Future; |
23 |
+ |
import java.util.concurrent.FutureTask; |
24 |
+ |
import java.util.concurrent.LinkedBlockingQueue; |
25 |
+ |
import java.util.concurrent.RejectedExecutionException; |
26 |
+ |
import java.util.concurrent.RejectedExecutionHandler; |
27 |
+ |
import java.util.concurrent.RunnableFuture; |
28 |
+ |
import java.util.concurrent.SynchronousQueue; |
29 |
+ |
import java.util.concurrent.ThreadFactory; |
30 |
+ |
import java.util.concurrent.ThreadPoolExecutor; |
31 |
+ |
import java.util.concurrent.TimeoutException; |
32 |
+ |
import java.util.concurrent.TimeUnit; |
33 |
|
import java.util.concurrent.locks.Condition; |
34 |
|
import java.util.concurrent.locks.ReentrantLock; |
35 |
< |
import java.util.*; |
35 |
> |
|
36 |
> |
import junit.framework.Test; |
37 |
> |
import junit.framework.TestSuite; |
38 |
|
|
39 |
|
public class ThreadPoolExecutorSubclassTest extends JSR166TestCase { |
40 |
|
public static void main(String[] args) { |
41 |
< |
junit.textui.TestRunner.run(suite()); |
41 |
> |
main(suite(), args); |
42 |
|
} |
43 |
|
public static Test suite() { |
44 |
|
return new TestSuite(ThreadPoolExecutorSubclassTest.class); |
60 |
|
CustomTask(final Runnable r, final V res) { |
61 |
|
if (r == null) throw new NullPointerException(); |
62 |
|
callable = new Callable<V>() { |
63 |
< |
public V call() throws Exception { r.run(); return res; }}; |
63 |
> |
public V call() throws Exception { r.run(); return res; }}; |
64 |
|
} |
65 |
|
public boolean isDone() { |
66 |
|
lock.lock(); try { return done; } finally { lock.unlock() ; } |
346 |
|
*/ |
347 |
|
public void testGetKeepAliveTime() { |
348 |
|
ThreadPoolExecutor p = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
349 |
< |
assertEquals(1, p.getKeepAliveTime(TimeUnit.SECONDS)); |
349 |
> |
assertEquals(1, p.getKeepAliveTime(SECONDS)); |
350 |
|
joinPool(p); |
351 |
|
} |
352 |
|
|
724 |
|
*/ |
725 |
|
public void testConstructor1() { |
726 |
|
try { |
727 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
727 |
> |
new CustomTPE(-1, 1, 1L, SECONDS, |
728 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
729 |
|
shouldThrow(); |
730 |
|
} catch (IllegalArgumentException success) {} |
731 |
|
} |
735 |
|
*/ |
736 |
|
public void testConstructor2() { |
737 |
|
try { |
738 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
738 |
> |
new CustomTPE(1, -1, 1L, SECONDS, |
739 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
740 |
|
shouldThrow(); |
741 |
|
} catch (IllegalArgumentException success) {} |
742 |
|
} |
746 |
|
*/ |
747 |
|
public void testConstructor3() { |
748 |
|
try { |
749 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
749 |
> |
new CustomTPE(1, 0, 1L, SECONDS, |
750 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
751 |
|
shouldThrow(); |
752 |
|
} catch (IllegalArgumentException success) {} |
753 |
|
} |
757 |
|
*/ |
758 |
|
public void testConstructor4() { |
759 |
|
try { |
760 |
< |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
760 |
> |
new CustomTPE(1, 2, -1L, SECONDS, |
761 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
762 |
|
shouldThrow(); |
763 |
|
} catch (IllegalArgumentException success) {} |
764 |
|
} |
768 |
|
*/ |
769 |
|
public void testConstructor5() { |
770 |
|
try { |
771 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
771 |
> |
new CustomTPE(2, 1, 1L, SECONDS, |
772 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
773 |
|
shouldThrow(); |
774 |
|
} catch (IllegalArgumentException success) {} |
775 |
|
} |
779 |
|
*/ |
780 |
|
public void testConstructorNullPointerException() { |
781 |
|
try { |
782 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null); |
782 |
> |
new CustomTPE(1, 2, 1L, SECONDS, null); |
783 |
|
shouldThrow(); |
784 |
|
} catch (NullPointerException success) {} |
785 |
|
} |
789 |
|
*/ |
790 |
|
public void testConstructor6() { |
791 |
|
try { |
792 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
792 |
> |
new CustomTPE(-1, 1, 1L, SECONDS, |
793 |
> |
new ArrayBlockingQueue<Runnable>(10), |
794 |
> |
new SimpleThreadFactory()); |
795 |
|
shouldThrow(); |
796 |
|
} catch (IllegalArgumentException success) {} |
797 |
|
} |
801 |
|
*/ |
802 |
|
public void testConstructor7() { |
803 |
|
try { |
804 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
804 |
> |
new CustomTPE(1,-1, 1L, SECONDS, |
805 |
> |
new ArrayBlockingQueue<Runnable>(10), |
806 |
> |
new SimpleThreadFactory()); |
807 |
|
shouldThrow(); |
808 |
|
} catch (IllegalArgumentException success) {} |
809 |
|
} |
813 |
|
*/ |
814 |
|
public void testConstructor8() { |
815 |
|
try { |
816 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
816 |
> |
new CustomTPE(1, 0, 1L, SECONDS, |
817 |
> |
new ArrayBlockingQueue<Runnable>(10), |
818 |
> |
new SimpleThreadFactory()); |
819 |
|
shouldThrow(); |
820 |
|
} catch (IllegalArgumentException success) {} |
821 |
|
} |
825 |
|
*/ |
826 |
|
public void testConstructor9() { |
827 |
|
try { |
828 |
< |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
828 |
> |
new CustomTPE(1, 2, -1L, SECONDS, |
829 |
> |
new ArrayBlockingQueue<Runnable>(10), |
830 |
> |
new SimpleThreadFactory()); |
831 |
|
shouldThrow(); |
832 |
|
} catch (IllegalArgumentException success) {} |
833 |
|
} |
837 |
|
*/ |
838 |
|
public void testConstructor10() { |
839 |
|
try { |
840 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
840 |
> |
new CustomTPE(2, 1, 1L, SECONDS, |
841 |
> |
new ArrayBlockingQueue<Runnable>(10), |
842 |
> |
new SimpleThreadFactory()); |
843 |
|
shouldThrow(); |
844 |
|
} catch (IllegalArgumentException success) {} |
845 |
|
} |
849 |
|
*/ |
850 |
|
public void testConstructorNullPointerException2() { |
851 |
|
try { |
852 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory()); |
852 |
> |
new CustomTPE(1, 2, 1L, SECONDS, null, new SimpleThreadFactory()); |
853 |
|
shouldThrow(); |
854 |
|
} catch (NullPointerException success) {} |
855 |
|
} |
859 |
|
*/ |
860 |
|
public void testConstructorNullPointerException3() { |
861 |
|
try { |
862 |
< |
ThreadFactory f = null; |
863 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f); |
862 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
863 |
> |
new ArrayBlockingQueue<Runnable>(10), |
864 |
> |
(ThreadFactory) null); |
865 |
|
shouldThrow(); |
866 |
|
} catch (NullPointerException success) {} |
867 |
|
} |
871 |
|
*/ |
872 |
|
public void testConstructor11() { |
873 |
|
try { |
874 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
874 |
> |
new CustomTPE(-1, 1, 1L, SECONDS, |
875 |
> |
new ArrayBlockingQueue<Runnable>(10), |
876 |
> |
new NoOpREHandler()); |
877 |
|
shouldThrow(); |
878 |
|
} catch (IllegalArgumentException success) {} |
879 |
|
} |
883 |
|
*/ |
884 |
|
public void testConstructor12() { |
885 |
|
try { |
886 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
886 |
> |
new CustomTPE(1, -1, 1L, SECONDS, |
887 |
> |
new ArrayBlockingQueue<Runnable>(10), |
888 |
> |
new NoOpREHandler()); |
889 |
|
shouldThrow(); |
890 |
|
} catch (IllegalArgumentException success) {} |
891 |
|
} |
895 |
|
*/ |
896 |
|
public void testConstructor13() { |
897 |
|
try { |
898 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
898 |
> |
new CustomTPE(1, 0, 1L, SECONDS, |
899 |
> |
new ArrayBlockingQueue<Runnable>(10), |
900 |
> |
new NoOpREHandler()); |
901 |
|
shouldThrow(); |
902 |
|
} catch (IllegalArgumentException success) {} |
903 |
|
} |
907 |
|
*/ |
908 |
|
public void testConstructor14() { |
909 |
|
try { |
910 |
< |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
910 |
> |
new CustomTPE(1, 2, -1L, SECONDS, |
911 |
> |
new ArrayBlockingQueue<Runnable>(10), |
912 |
> |
new NoOpREHandler()); |
913 |
|
shouldThrow(); |
914 |
|
} catch (IllegalArgumentException success) {} |
915 |
|
} |
919 |
|
*/ |
920 |
|
public void testConstructor15() { |
921 |
|
try { |
922 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
922 |
> |
new CustomTPE(2, 1, 1L, SECONDS, |
923 |
> |
new ArrayBlockingQueue<Runnable>(10), |
924 |
> |
new NoOpREHandler()); |
925 |
|
shouldThrow(); |
926 |
|
} catch (IllegalArgumentException success) {} |
927 |
|
} |
931 |
|
*/ |
932 |
|
public void testConstructorNullPointerException4() { |
933 |
|
try { |
934 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler()); |
934 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
935 |
> |
null, |
936 |
> |
new NoOpREHandler()); |
937 |
|
shouldThrow(); |
938 |
|
} catch (NullPointerException success) {} |
939 |
|
} |
943 |
|
*/ |
944 |
|
public void testConstructorNullPointerException5() { |
945 |
|
try { |
946 |
< |
RejectedExecutionHandler r = null; |
947 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r); |
946 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
947 |
> |
new ArrayBlockingQueue<Runnable>(10), |
948 |
> |
(RejectedExecutionHandler) null); |
949 |
|
shouldThrow(); |
950 |
|
} catch (NullPointerException success) {} |
951 |
|
} |
955 |
|
*/ |
956 |
|
public void testConstructor16() { |
957 |
|
try { |
958 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
958 |
> |
new CustomTPE(-1, 1, 1L, SECONDS, |
959 |
> |
new ArrayBlockingQueue<Runnable>(10), |
960 |
> |
new SimpleThreadFactory(), |
961 |
> |
new NoOpREHandler()); |
962 |
|
shouldThrow(); |
963 |
|
} catch (IllegalArgumentException success) {} |
964 |
|
} |
968 |
|
*/ |
969 |
|
public void testConstructor17() { |
970 |
|
try { |
971 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
971 |
> |
new CustomTPE(1, -1, 1L, SECONDS, |
972 |
> |
new ArrayBlockingQueue<Runnable>(10), |
973 |
> |
new SimpleThreadFactory(), |
974 |
> |
new NoOpREHandler()); |
975 |
|
shouldThrow(); |
976 |
|
} catch (IllegalArgumentException success) {} |
977 |
|
} |
981 |
|
*/ |
982 |
|
public void testConstructor18() { |
983 |
|
try { |
984 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
984 |
> |
new CustomTPE(1, 0, 1L, SECONDS, |
985 |
> |
new ArrayBlockingQueue<Runnable>(10), |
986 |
> |
new SimpleThreadFactory(), |
987 |
> |
new NoOpREHandler()); |
988 |
|
shouldThrow(); |
989 |
|
} catch (IllegalArgumentException success) {} |
990 |
|
} |
994 |
|
*/ |
995 |
|
public void testConstructor19() { |
996 |
|
try { |
997 |
< |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
997 |
> |
new CustomTPE(1, 2, -1L, SECONDS, |
998 |
> |
new ArrayBlockingQueue<Runnable>(10), |
999 |
> |
new SimpleThreadFactory(), |
1000 |
> |
new NoOpREHandler()); |
1001 |
|
shouldThrow(); |
1002 |
|
} catch (IllegalArgumentException success) {} |
1003 |
|
} |
1007 |
|
*/ |
1008 |
|
public void testConstructor20() { |
1009 |
|
try { |
1010 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
1010 |
> |
new CustomTPE(2, 1, 1L, SECONDS, |
1011 |
> |
new ArrayBlockingQueue<Runnable>(10), |
1012 |
> |
new SimpleThreadFactory(), |
1013 |
> |
new NoOpREHandler()); |
1014 |
|
shouldThrow(); |
1015 |
|
} catch (IllegalArgumentException success) {} |
1016 |
|
} |
1020 |
|
*/ |
1021 |
|
public void testConstructorNullPointerException6() { |
1022 |
|
try { |
1023 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); |
1023 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
1024 |
> |
null, |
1025 |
> |
new SimpleThreadFactory(), |
1026 |
> |
new NoOpREHandler()); |
1027 |
|
shouldThrow(); |
1028 |
|
} catch (NullPointerException success) {} |
1029 |
|
} |
1033 |
|
*/ |
1034 |
|
public void testConstructorNullPointerException7() { |
1035 |
|
try { |
1036 |
< |
RejectedExecutionHandler r = null; |
1037 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r); |
1036 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
1037 |
> |
new ArrayBlockingQueue<Runnable>(10), |
1038 |
> |
new SimpleThreadFactory(), |
1039 |
> |
(RejectedExecutionHandler) null); |
1040 |
|
shouldThrow(); |
1041 |
|
} catch (NullPointerException success) {} |
1042 |
|
} |
1046 |
|
*/ |
1047 |
|
public void testConstructorNullPointerException8() { |
1048 |
|
try { |
1049 |
< |
new CustomTPE(1, 2, |
978 |
< |
LONG_DELAY_MS, MILLISECONDS, |
1049 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
1050 |
|
new ArrayBlockingQueue<Runnable>(10), |
1051 |
|
(ThreadFactory) null, |
1052 |
|
new NoOpREHandler()); |
1224 |
|
* execute(null) throws NPE |
1225 |
|
*/ |
1226 |
|
public void testExecuteNull() { |
1227 |
< |
ThreadPoolExecutor p = null; |
1227 |
> |
ThreadPoolExecutor p = |
1228 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
1229 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
1230 |
|
try { |
1158 |
– |
p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1231 |
|
p.execute(null); |
1232 |
|
shouldThrow(); |
1233 |
|
} catch (NullPointerException success) {} |
1738 |
|
public void testTimedInvokeAll6() throws Exception { |
1739 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1740 |
|
try { |
1741 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1742 |
< |
l.add(new StringTask()); |
1743 |
< |
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
1744 |
< |
l.add(new StringTask()); |
1745 |
< |
List<Future<String>> futures = |
1746 |
< |
e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
1747 |
< |
assertEquals(l.size(), futures.size()); |
1748 |
< |
for (Future future : futures) |
1749 |
< |
assertTrue(future.isDone()); |
1750 |
< |
assertFalse(futures.get(0).isCancelled()); |
1751 |
< |
assertTrue(futures.get(1).isCancelled()); |
1741 |
> |
for (long timeout = timeoutMillis();;) { |
1742 |
> |
List<Callable<String>> tasks = new ArrayList<>(); |
1743 |
> |
tasks.add(new StringTask("0")); |
1744 |
> |
tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING)); |
1745 |
> |
tasks.add(new StringTask("2")); |
1746 |
> |
long startTime = System.nanoTime(); |
1747 |
> |
List<Future<String>> futures = |
1748 |
> |
e.invokeAll(tasks, timeout, MILLISECONDS); |
1749 |
> |
assertEquals(tasks.size(), futures.size()); |
1750 |
> |
assertTrue(millisElapsedSince(startTime) >= timeout); |
1751 |
> |
for (Future future : futures) |
1752 |
> |
assertTrue(future.isDone()); |
1753 |
> |
assertTrue(futures.get(1).isCancelled()); |
1754 |
> |
try { |
1755 |
> |
assertEquals("0", futures.get(0).get()); |
1756 |
> |
assertEquals("2", futures.get(2).get()); |
1757 |
> |
break; |
1758 |
> |
} catch (CancellationException retryWithLongerTimeout) { |
1759 |
> |
timeout *= 2; |
1760 |
> |
if (timeout >= LONG_DELAY_MS / 2) |
1761 |
> |
fail("expected exactly one task to be cancelled"); |
1762 |
> |
} |
1763 |
> |
} |
1764 |
|
} finally { |
1765 |
|
joinPool(e); |
1766 |
|
} |
1803 |
|
* allowCoreThreadTimeOut(true) causes idle threads to time out |
1804 |
|
*/ |
1805 |
|
public void testAllowCoreThreadTimeOut_true() throws Exception { |
1806 |
< |
long coreThreadTimeOut = SHORT_DELAY_MS; |
1806 |
> |
long keepAliveTime = timeoutMillis(); |
1807 |
|
final ThreadPoolExecutor p = |
1808 |
|
new CustomTPE(2, 10, |
1809 |
< |
coreThreadTimeOut, MILLISECONDS, |
1809 |
> |
keepAliveTime, MILLISECONDS, |
1810 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1811 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
1812 |
|
try { |
1813 |
|
p.allowCoreThreadTimeOut(true); |
1814 |
|
p.execute(new CheckedRunnable() { |
1815 |
< |
public void realRun() throws InterruptedException { |
1815 |
> |
public void realRun() { |
1816 |
|
threadStarted.countDown(); |
1817 |
|
assertEquals(1, p.getPoolSize()); |
1818 |
|
}}); |
1819 |
|
await(threadStarted); |
1820 |
< |
delay(coreThreadTimeOut); |
1820 |
> |
delay(keepAliveTime); |
1821 |
|
long startTime = System.nanoTime(); |
1822 |
|
while (p.getPoolSize() > 0 |
1823 |
|
&& millisElapsedSince(startTime) < LONG_DELAY_MS) |
1833 |
|
* allowCoreThreadTimeOut(false) causes idle threads not to time out |
1834 |
|
*/ |
1835 |
|
public void testAllowCoreThreadTimeOut_false() throws Exception { |
1836 |
< |
long coreThreadTimeOut = SHORT_DELAY_MS; |
1836 |
> |
long keepAliveTime = timeoutMillis(); |
1837 |
|
final ThreadPoolExecutor p = |
1838 |
|
new CustomTPE(2, 10, |
1839 |
< |
coreThreadTimeOut, MILLISECONDS, |
1839 |
> |
keepAliveTime, MILLISECONDS, |
1840 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1841 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
1842 |
|
try { |
1846 |
|
threadStarted.countDown(); |
1847 |
|
assertTrue(p.getPoolSize() >= 1); |
1848 |
|
}}); |
1849 |
< |
delay(2 * coreThreadTimeOut); |
1849 |
> |
delay(2 * keepAliveTime); |
1850 |
|
assertTrue(p.getPoolSize() >= 1); |
1851 |
|
} finally { |
1852 |
|
joinPool(p); |