1870 |
|
* timed invokeAll(c) cancels tasks not completed by timeout |
1871 |
|
*/ |
1872 |
|
public void testTimedInvokeAll6() throws Exception { |
1873 |
< |
final ExecutorService e = |
1874 |
< |
new ThreadPoolExecutor(2, 2, |
1875 |
< |
LONG_DELAY_MS, MILLISECONDS, |
1876 |
< |
new ArrayBlockingQueue<Runnable>(10)); |
1877 |
< |
try (PoolCleaner cleaner = cleaner(e)) { |
1878 |
< |
for (long timeout = timeoutMillis();;) { |
1873 |
> |
for (long timeout = timeoutMillis();;) { |
1874 |
> |
final CountDownLatch done = new CountDownLatch(1); |
1875 |
> |
final Callable<String> waiter = new CheckedCallable<String>() { |
1876 |
> |
public String realCall() { |
1877 |
> |
try { done.await(LONG_DELAY_MS, MILLISECONDS); } |
1878 |
> |
catch (InterruptedException ok) {} |
1879 |
> |
return "1"; }}; |
1880 |
> |
final ExecutorService p = |
1881 |
> |
new ThreadPoolExecutor(2, 2, |
1882 |
> |
LONG_DELAY_MS, MILLISECONDS, |
1883 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
1884 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
1885 |
|
List<Callable<String>> tasks = new ArrayList<>(); |
1886 |
|
tasks.add(new StringTask("0")); |
1887 |
< |
tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING)); |
1887 |
> |
tasks.add(waiter); |
1888 |
|
tasks.add(new StringTask("2")); |
1889 |
|
long startTime = System.nanoTime(); |
1890 |
|
List<Future<String>> futures = |
1891 |
< |
e.invokeAll(tasks, timeout, MILLISECONDS); |
1891 |
> |
p.invokeAll(tasks, timeout, MILLISECONDS); |
1892 |
|
assertEquals(tasks.size(), futures.size()); |
1893 |
|
assertTrue(millisElapsedSince(startTime) >= timeout); |
1894 |
|
for (Future future : futures) |