ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java (file contents):
Revision 1.6 by jsr166, Fri Nov 20 06:33:25 2009 UTC vs.
Revision 1.21 by jsr166, Mon Oct 11 07:21:32 2010 UTC

# Line 7 | Line 7
7   */
8  
9   import java.util.concurrent.*;
10 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
11   import java.util.concurrent.locks.*;
12  
13   import junit.framework.*;
# Line 14 | Line 15 | import java.util.*;
15  
16   public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
17      public static void main(String[] args) {
18 <        junit.textui.TestRunner.run(suite());
18 >        junit.textui.TestRunner.run(suite());
19      }
20      public static Test suite() {
21          return new TestSuite(ThreadPoolExecutorSubclassTest.class);
# Line 167 | Line 168 | public class ThreadPoolExecutorSubclassT
168          volatile boolean afterCalled = false;
169          volatile boolean terminatedCalled = false;
170          public CustomTPE() {
171 <            super(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
171 >            super(1, 1, LONG_DELAY_MS, MILLISECONDS, new SynchronousQueue<Runnable>());
172          }
173          protected void beforeExecute(Thread t, Runnable r) {
174              beforeCalled = true;
# Line 191 | Line 192 | public class ThreadPoolExecutorSubclassT
192  
193  
194      /**
195 <     *  execute successfully executes a runnable
195 >     * execute successfully executes a runnable
196       */
197      public void testExecute() throws InterruptedException {
198 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
198 >        final ThreadPoolExecutor p =
199 >            new CustomTPE(1, 1,
200 >                          LONG_DELAY_MS, MILLISECONDS,
201 >                          new ArrayBlockingQueue<Runnable>(10));
202 >        final CountDownLatch done = new CountDownLatch(1);
203 >        final Runnable task = new CheckedRunnable() {
204 >            public void realRun() {
205 >                done.countDown();
206 >            }};
207          try {
208 <            p1.execute(new ShortRunnable());
209 <            Thread.sleep(SMALL_DELAY_MS);
208 >            p.execute(task);
209 >            assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
210          } finally {
211 <            joinPool(p1);
211 >            joinPool(p);
212          }
213      }
214  
215      /**
216 <     *  getActiveCount increases but doesn't overestimate, when a
217 <     *  thread becomes active
216 >     * getActiveCount increases but doesn't overestimate, when a
217 >     * thread becomes active
218       */
219      public void testGetActiveCount() throws InterruptedException {
220 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
221 <        assertEquals(0, p2.getActiveCount());
222 <        p2.execute(new MediumRunnable());
223 <        Thread.sleep(SHORT_DELAY_MS);
224 <        assertEquals(1, p2.getActiveCount());
225 <        joinPool(p2);
220 >        final ThreadPoolExecutor p =
221 >            new CustomTPE(2, 2,
222 >                          LONG_DELAY_MS, MILLISECONDS,
223 >                          new ArrayBlockingQueue<Runnable>(10));
224 >        final CountDownLatch threadStarted = new CountDownLatch(1);
225 >        final CountDownLatch done = new CountDownLatch(1);
226 >        try {
227 >            assertEquals(0, p.getActiveCount());
228 >            p.execute(new CheckedRunnable() {
229 >                public void realRun() throws InterruptedException {
230 >                    threadStarted.countDown();
231 >                    assertEquals(1, p.getActiveCount());
232 >                    done.await();
233 >                }});
234 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
235 >            assertEquals(1, p.getActiveCount());
236 >        } finally {
237 >            done.countDown();
238 >            joinPool(p);
239 >        }
240      }
241  
242      /**
243 <     *  prestartCoreThread starts a thread if under corePoolSize, else doesn't
243 >     * prestartCoreThread starts a thread if under corePoolSize, else doesn't
244       */
245      public void testPrestartCoreThread() {
246 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
247 <        assertEquals(0, p2.getPoolSize());
248 <        assertTrue(p2.prestartCoreThread());
249 <        assertEquals(1, p2.getPoolSize());
250 <        assertTrue(p2.prestartCoreThread());
251 <        assertEquals(2, p2.getPoolSize());
252 <        assertFalse(p2.prestartCoreThread());
253 <        assertEquals(2, p2.getPoolSize());
254 <        joinPool(p2);
246 >        ThreadPoolExecutor p = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
247 >        assertEquals(0, p.getPoolSize());
248 >        assertTrue(p.prestartCoreThread());
249 >        assertEquals(1, p.getPoolSize());
250 >        assertTrue(p.prestartCoreThread());
251 >        assertEquals(2, p.getPoolSize());
252 >        assertFalse(p.prestartCoreThread());
253 >        assertEquals(2, p.getPoolSize());
254 >        joinPool(p);
255      }
256  
257      /**
258 <     *  prestartAllCoreThreads starts all corePoolSize threads
258 >     * prestartAllCoreThreads starts all corePoolSize threads
259       */
260      public void testPrestartAllCoreThreads() {
261 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
262 <        assertEquals(0, p2.getPoolSize());
263 <        p2.prestartAllCoreThreads();
264 <        assertEquals(2, p2.getPoolSize());
265 <        p2.prestartAllCoreThreads();
266 <        assertEquals(2, p2.getPoolSize());
267 <        joinPool(p2);
261 >        ThreadPoolExecutor p = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
262 >        assertEquals(0, p.getPoolSize());
263 >        p.prestartAllCoreThreads();
264 >        assertEquals(2, p.getPoolSize());
265 >        p.prestartAllCoreThreads();
266 >        assertEquals(2, p.getPoolSize());
267 >        joinPool(p);
268      }
269  
270      /**
271 <     *   getCompletedTaskCount increases, but doesn't overestimate,
272 <     *   when tasks complete
271 >     * getCompletedTaskCount increases, but doesn't overestimate,
272 >     * when tasks complete
273       */
274      public void testGetCompletedTaskCount() throws InterruptedException {
275 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
276 <        assertEquals(0, p2.getCompletedTaskCount());
277 <        p2.execute(new ShortRunnable());
278 <        Thread.sleep(SMALL_DELAY_MS);
279 <        assertEquals(1, p2.getCompletedTaskCount());
280 <        try { p2.shutdown(); } catch (SecurityException ok) { return; }
281 <        joinPool(p2);
275 >        final ThreadPoolExecutor p =
276 >            new CustomTPE(2, 2,
277 >                          LONG_DELAY_MS, MILLISECONDS,
278 >                          new ArrayBlockingQueue<Runnable>(10));
279 >        final CountDownLatch threadStarted = new CountDownLatch(1);
280 >        final CountDownLatch threadProceed = new CountDownLatch(1);
281 >        final CountDownLatch threadDone = new CountDownLatch(1);
282 >        try {
283 >            assertEquals(0, p.getCompletedTaskCount());
284 >            p.execute(new CheckedRunnable() {
285 >                public void realRun() throws InterruptedException {
286 >                    threadStarted.countDown();
287 >                    assertEquals(0, p.getCompletedTaskCount());
288 >                    threadProceed.await();
289 >                    threadDone.countDown();
290 >                }});
291 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
292 >            assertEquals(0, p.getCompletedTaskCount());
293 >            threadProceed.countDown();
294 >            threadDone.await();
295 >            Thread.sleep(SHORT_DELAY_MS);
296 >            assertEquals(1, p.getCompletedTaskCount());
297 >        } finally {
298 >            joinPool(p);
299 >        }
300      }
301  
302      /**
303 <     *   getCorePoolSize returns size given in constructor if not otherwise set
303 >     * getCorePoolSize returns size given in constructor if not otherwise set
304       */
305      public void testGetCorePoolSize() {
306 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
307 <        assertEquals(1, p1.getCorePoolSize());
308 <        joinPool(p1);
306 >        ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
307 >        assertEquals(1, p.getCorePoolSize());
308 >        joinPool(p);
309      }
310  
311      /**
312 <     *   getKeepAliveTime returns value given in constructor if not otherwise set
312 >     * getKeepAliveTime returns value given in constructor if not otherwise set
313       */
314      public void testGetKeepAliveTime() {
315 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
316 <        assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS));
317 <        joinPool(p2);
315 >        ThreadPoolExecutor p = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
316 >        assertEquals(1, p.getKeepAliveTime(TimeUnit.SECONDS));
317 >        joinPool(p);
318      }
319  
320  
# Line 282 | Line 323 | public class ThreadPoolExecutorSubclassT
323       */
324      public void testGetThreadFactory() {
325          ThreadFactory tf = new SimpleThreadFactory();
326 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler());
326 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler());
327          assertSame(tf, p.getThreadFactory());
328          joinPool(p);
329      }
# Line 291 | Line 332 | public class ThreadPoolExecutorSubclassT
332       * setThreadFactory sets the thread factory returned by getThreadFactory
333       */
334      public void testSetThreadFactory() {
335 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
335 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
336          ThreadFactory tf = new SimpleThreadFactory();
337          p.setThreadFactory(tf);
338          assertSame(tf, p.getThreadFactory());
# Line 303 | Line 344 | public class ThreadPoolExecutorSubclassT
344       * setThreadFactory(null) throws NPE
345       */
346      public void testSetThreadFactoryNull() {
347 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
347 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
348          try {
349              p.setThreadFactory(null);
350              shouldThrow();
# Line 318 | Line 359 | public class ThreadPoolExecutorSubclassT
359       */
360      public void testGetRejectedExecutionHandler() {
361          RejectedExecutionHandler h = new NoOpREHandler();
362 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
362 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h);
363          assertSame(h, p.getRejectedExecutionHandler());
364          joinPool(p);
365      }
# Line 328 | Line 369 | public class ThreadPoolExecutorSubclassT
369       * getRejectedExecutionHandler
370       */
371      public void testSetRejectedExecutionHandler() {
372 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
372 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
373          RejectedExecutionHandler h = new NoOpREHandler();
374          p.setRejectedExecutionHandler(h);
375          assertSame(h, p.getRejectedExecutionHandler());
# Line 340 | Line 381 | public class ThreadPoolExecutorSubclassT
381       * setRejectedExecutionHandler(null) throws NPE
382       */
383      public void testSetRejectedExecutionHandlerNull() {
384 <        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
384 >        ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
385          try {
386              p.setRejectedExecutionHandler(null);
387              shouldThrow();
# Line 352 | Line 393 | public class ThreadPoolExecutorSubclassT
393  
394  
395      /**
396 <     *   getLargestPoolSize increases, but doesn't overestimate, when
397 <     *   multiple threads active
396 >     * getLargestPoolSize increases, but doesn't overestimate, when
397 >     * multiple threads active
398       */
399      public void testGetLargestPoolSize() throws InterruptedException {
400 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
401 <        assertEquals(0, p2.getLargestPoolSize());
402 <        p2.execute(new MediumRunnable());
403 <        p2.execute(new MediumRunnable());
404 <        Thread.sleep(SHORT_DELAY_MS);
405 <        assertEquals(2, p2.getLargestPoolSize());
406 <        joinPool(p2);
400 >        final int THREADS = 3;
401 >        final ThreadPoolExecutor p =
402 >            new CustomTPE(THREADS, THREADS,
403 >                          LONG_DELAY_MS, MILLISECONDS,
404 >                          new ArrayBlockingQueue<Runnable>(10));
405 >        final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
406 >        final CountDownLatch done = new CountDownLatch(1);
407 >        try {
408 >            assertEquals(0, p.getLargestPoolSize());
409 >            for (int i = 0; i < THREADS; i++)
410 >                p.execute(new CheckedRunnable() {
411 >                    public void realRun() throws InterruptedException {
412 >                        threadsStarted.countDown();
413 >                        done.await();
414 >                        assertEquals(THREADS, p.getLargestPoolSize());
415 >                    }});
416 >            assertTrue(threadsStarted.await(SMALL_DELAY_MS, MILLISECONDS));
417 >            assertEquals(THREADS, p.getLargestPoolSize());
418 >        } finally {
419 >            done.countDown();
420 >            joinPool(p);
421 >            assertEquals(THREADS, p.getLargestPoolSize());
422 >        }
423      }
424  
425      /**
426 <     *   getMaximumPoolSize returns value given in constructor if not
427 <     *   otherwise set
426 >     * getMaximumPoolSize returns value given in constructor if not
427 >     * otherwise set
428       */
429      public void testGetMaximumPoolSize() {
430 <        ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
431 <        assertEquals(2, p2.getMaximumPoolSize());
432 <        joinPool(p2);
430 >        ThreadPoolExecutor p = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
431 >        assertEquals(2, p.getMaximumPoolSize());
432 >        joinPool(p);
433      }
434  
435      /**
436 <     *   getPoolSize increases, but doesn't overestimate, when threads
437 <     *   become active
436 >     * getPoolSize increases, but doesn't overestimate, when threads
437 >     * become active
438       */
439 <    public void testGetPoolSize() {
440 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
441 <        assertEquals(0, p1.getPoolSize());
442 <        p1.execute(new MediumRunnable());
443 <        assertEquals(1, p1.getPoolSize());
444 <        joinPool(p1);
439 >    public void testGetPoolSize() throws InterruptedException {
440 >        final ThreadPoolExecutor p =
441 >            new CustomTPE(1, 1,
442 >                          LONG_DELAY_MS, MILLISECONDS,
443 >                          new ArrayBlockingQueue<Runnable>(10));
444 >        final CountDownLatch threadStarted = new CountDownLatch(1);
445 >        final CountDownLatch done = new CountDownLatch(1);
446 >        try {
447 >            assertEquals(0, p.getPoolSize());
448 >            p.execute(new CheckedRunnable() {
449 >                public void realRun() throws InterruptedException {
450 >                    threadStarted.countDown();
451 >                    assertEquals(1, p.getPoolSize());
452 >                    done.await();
453 >                }});
454 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
455 >            assertEquals(1, p.getPoolSize());
456 >        } finally {
457 >            done.countDown();
458 >            joinPool(p);
459 >        }
460      }
461  
462      /**
463 <     *  getTaskCount increases, but doesn't overestimate, when tasks submitted
463 >     * getTaskCount increases, but doesn't overestimate, when tasks submitted
464       */
465      public void testGetTaskCount() throws InterruptedException {
466 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
467 <        assertEquals(0, p1.getTaskCount());
468 <        p1.execute(new MediumRunnable());
469 <        Thread.sleep(SHORT_DELAY_MS);
470 <        assertEquals(1, p1.getTaskCount());
471 <        joinPool(p1);
466 >        final ThreadPoolExecutor p =
467 >            new CustomTPE(1, 1,
468 >                          LONG_DELAY_MS, MILLISECONDS,
469 >                          new ArrayBlockingQueue<Runnable>(10));
470 >        final CountDownLatch threadStarted = new CountDownLatch(1);
471 >        final CountDownLatch done = new CountDownLatch(1);
472 >        try {
473 >            assertEquals(0, p.getTaskCount());
474 >            p.execute(new CheckedRunnable() {
475 >                public void realRun() throws InterruptedException {
476 >                    threadStarted.countDown();
477 >                    assertEquals(1, p.getTaskCount());
478 >                    done.await();
479 >                }});
480 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
481 >            assertEquals(1, p.getTaskCount());
482 >        } finally {
483 >            done.countDown();
484 >            joinPool(p);
485 >        }
486      }
487  
488      /**
489 <     *   isShutDown is false before shutdown, true after
489 >     * isShutDown is false before shutdown, true after
490       */
491      public void testIsShutdown() {
492  
493 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
494 <        assertFalse(p1.isShutdown());
495 <        try { p1.shutdown(); } catch (SecurityException ok) { return; }
496 <        assertTrue(p1.isShutdown());
497 <        joinPool(p1);
493 >        ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
494 >        assertFalse(p.isShutdown());
495 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
496 >        assertTrue(p.isShutdown());
497 >        joinPool(p);
498      }
499  
500  
501      /**
502 <     *  isTerminated is false before termination, true after
502 >     * isTerminated is false before termination, true after
503       */
504      public void testIsTerminated() throws InterruptedException {
505 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
506 <        assertFalse(p1.isTerminated());
507 <        try {
508 <            p1.execute(new MediumRunnable());
509 <        } finally {
510 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
511 <        }
512 <        assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
513 <        assertTrue(p1.isTerminated());
505 >        final ThreadPoolExecutor p =
506 >            new CustomTPE(1, 1,
507 >                          LONG_DELAY_MS, MILLISECONDS,
508 >                          new ArrayBlockingQueue<Runnable>(10));
509 >        final CountDownLatch threadStarted = new CountDownLatch(1);
510 >        final CountDownLatch done = new CountDownLatch(1);
511 >        try {
512 >            assertFalse(p.isTerminating());
513 >            p.execute(new CheckedRunnable() {
514 >                public void realRun() throws InterruptedException {
515 >                    threadStarted.countDown();
516 >                    assertFalse(p.isTerminating());
517 >                    done.await();
518 >                }});
519 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
520 >            assertFalse(p.isTerminating());
521 >            done.countDown();
522 >        } finally {
523 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
524 >        }
525 >        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
526 >        assertTrue(p.isTerminated());
527 >        assertFalse(p.isTerminating());
528      }
529  
530      /**
531 <     *  isTerminating is not true when running or when terminated
531 >     * isTerminating is not true when running or when terminated
532       */
533      public void testIsTerminating() throws InterruptedException {
534 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
535 <        assertFalse(p1.isTerminating());
536 <        try {
537 <            p1.execute(new SmallRunnable());
538 <            assertFalse(p1.isTerminating());
539 <        } finally {
540 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
541 <        }
542 <        assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
543 <        assertTrue(p1.isTerminated());
544 <        assertFalse(p1.isTerminating());
534 >        final ThreadPoolExecutor p =
535 >            new CustomTPE(1, 1,
536 >                          LONG_DELAY_MS, MILLISECONDS,
537 >                          new ArrayBlockingQueue<Runnable>(10));
538 >        final CountDownLatch threadStarted = new CountDownLatch(1);
539 >        final CountDownLatch done = new CountDownLatch(1);
540 >        try {
541 >            assertFalse(p.isTerminating());
542 >            p.execute(new CheckedRunnable() {
543 >                public void realRun() throws InterruptedException {
544 >                    threadStarted.countDown();
545 >                    assertFalse(p.isTerminating());
546 >                    done.await();
547 >                }});
548 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
549 >            assertFalse(p.isTerminating());
550 >            done.countDown();
551 >        } finally {
552 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
553 >        }
554 >        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
555 >        assertTrue(p.isTerminated());
556 >        assertFalse(p.isTerminating());
557      }
558  
559      /**
560       * getQueue returns the work queue, which contains queued tasks
561       */
562      public void testGetQueue() throws InterruptedException {
563 <        BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
564 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
565 <        FutureTask[] tasks = new FutureTask[5];
566 <        for (int i = 0; i < 5; i++) {
567 <            tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
568 <            p1.execute(tasks[i]);
569 <        }
570 <        try {
571 <            Thread.sleep(SHORT_DELAY_MS);
572 <            BlockingQueue<Runnable> wq = p1.getQueue();
573 <            assertSame(q, wq);
574 <            assertFalse(wq.contains(tasks[0]));
575 <            assertTrue(wq.contains(tasks[4]));
576 <            for (int i = 1; i < 5; ++i)
577 <                tasks[i].cancel(true);
578 <            p1.shutdownNow();
563 >        final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
564 >        final ThreadPoolExecutor p =
565 >            new CustomTPE(1, 1,
566 >                          LONG_DELAY_MS, MILLISECONDS,
567 >                          q);
568 >        final CountDownLatch threadStarted = new CountDownLatch(1);
569 >        final CountDownLatch done = new CountDownLatch(1);
570 >        try {
571 >            FutureTask[] tasks = new FutureTask[5];
572 >            for (int i = 0; i < tasks.length; i++) {
573 >                Callable task = new CheckedCallable<Boolean>() {
574 >                    public Boolean realCall() throws InterruptedException {
575 >                        threadStarted.countDown();
576 >                        assertSame(q, p.getQueue());
577 >                        done.await();
578 >                        return Boolean.TRUE;
579 >                    }};
580 >                tasks[i] = new FutureTask(task);
581 >                p.execute(tasks[i]);
582 >            }
583 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
584 >            assertSame(q, p.getQueue());
585 >            assertFalse(q.contains(tasks[0]));
586 >            assertTrue(q.contains(tasks[tasks.length - 1]));
587 >            assertEquals(tasks.length - 1, q.size());
588          } finally {
589 <            joinPool(p1);
589 >            done.countDown();
590 >            joinPool(p);
591          }
592      }
593  
# Line 474 | Line 596 | public class ThreadPoolExecutorSubclassT
596       */
597      public void testRemove() throws InterruptedException {
598          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
599 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
600 <        FutureTask[] tasks = new FutureTask[5];
601 <        for (int i = 0; i < 5; i++) {
602 <            tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
603 <            p1.execute(tasks[i]);
604 <        }
605 <        try {
606 <            Thread.sleep(SHORT_DELAY_MS);
607 <            assertFalse(p1.remove(tasks[0]));
599 >        final ThreadPoolExecutor p =
600 >            new CustomTPE(1, 1,
601 >                          LONG_DELAY_MS, MILLISECONDS,
602 >                          q);
603 >        Runnable[] tasks = new Runnable[6];
604 >        final CountDownLatch threadStarted = new CountDownLatch(1);
605 >        final CountDownLatch done = new CountDownLatch(1);
606 >        try {
607 >            for (int i = 0; i < tasks.length; i++) {
608 >                tasks[i] = new CheckedRunnable() {
609 >                        public void realRun() throws InterruptedException {
610 >                            threadStarted.countDown();
611 >                            done.await();
612 >                        }};
613 >                p.execute(tasks[i]);
614 >            }
615 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
616 >            assertFalse(p.remove(tasks[0]));
617              assertTrue(q.contains(tasks[4]));
618              assertTrue(q.contains(tasks[3]));
619 <            assertTrue(p1.remove(tasks[4]));
620 <            assertFalse(p1.remove(tasks[4]));
619 >            assertTrue(p.remove(tasks[4]));
620 >            assertFalse(p.remove(tasks[4]));
621              assertFalse(q.contains(tasks[4]));
622              assertTrue(q.contains(tasks[3]));
623 <            assertTrue(p1.remove(tasks[3]));
623 >            assertTrue(p.remove(tasks[3]));
624              assertFalse(q.contains(tasks[3]));
625          } finally {
626 <            joinPool(p1);
626 >            done.countDown();
627 >            joinPool(p);
628          }
629      }
630  
631      /**
632 <     *   purge removes cancelled tasks from the queue
632 >     * purge removes cancelled tasks from the queue
633       */
634 <    public void testPurge() {
635 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
634 >    public void testPurge() throws InterruptedException {
635 >        final CountDownLatch threadStarted = new CountDownLatch(1);
636 >        final CountDownLatch done = new CountDownLatch(1);
637 >        final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
638 >        final ThreadPoolExecutor p =
639 >            new CustomTPE(1, 1,
640 >                          LONG_DELAY_MS, MILLISECONDS,
641 >                          q);
642          FutureTask[] tasks = new FutureTask[5];
643 <        for (int i = 0; i < 5; i++) {
644 <            tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
645 <            p1.execute(tasks[i]);
643 >        try {
644 >            for (int i = 0; i < tasks.length; i++) {
645 >                Callable task = new CheckedCallable<Boolean>() {
646 >                    public Boolean realCall() throws InterruptedException {
647 >                        threadStarted.countDown();
648 >                        done.await();
649 >                        return Boolean.TRUE;
650 >                    }};
651 >                tasks[i] = new FutureTask(task);
652 >                p.execute(tasks[i]);
653 >            }
654 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
655 >            assertEquals(tasks.length, p.getTaskCount());
656 >            assertEquals(tasks.length - 1, q.size());
657 >            assertEquals(1L, p.getActiveCount());
658 >            assertEquals(0L, p.getCompletedTaskCount());
659 >            tasks[4].cancel(true);
660 >            tasks[3].cancel(false);
661 >            p.purge();
662 >            assertEquals(tasks.length - 3, q.size());
663 >            assertEquals(tasks.length - 2, p.getTaskCount());
664 >            p.purge();         // Nothing to do
665 >            assertEquals(tasks.length - 3, q.size());
666 >            assertEquals(tasks.length - 2, p.getTaskCount());
667 >        } finally {
668 >            done.countDown();
669 >            joinPool(p);
670          }
509        tasks[4].cancel(true);
510        tasks[3].cancel(true);
511        p1.purge();
512        long count = p1.getTaskCount();
513        assertTrue(count >= 2 && count < 5);
514        joinPool(p1);
671      }
672  
673      /**
674 <     *  shutDownNow returns a list containing tasks that were not run
674 >     * shutDownNow returns a list containing tasks that were not run
675       */
676      public void testShutDownNow() {
677 <        ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
677 >        ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
678          List l;
679          try {
680              for (int i = 0; i < 5; i++)
681 <                p1.execute(new MediumPossiblyInterruptedRunnable());
681 >                p.execute(new MediumPossiblyInterruptedRunnable());
682          }
683          finally {
684              try {
685 <                l = p1.shutdownNow();
685 >                l = p.shutdownNow();
686              } catch (SecurityException ok) { return; }
531
687          }
688 <        assertTrue(p1.isShutdown());
689 <        assertTrue(l.size() <= 4);
688 >        assertTrue(p.isShutdown());
689 >        assertTrue(l.size() <= 4);
690      }
691  
692      // Exception Tests
# Line 542 | Line 697 | public class ThreadPoolExecutorSubclassT
697       */
698      public void testConstructor1() {
699          try {
700 <            new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
700 >            new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
701              shouldThrow();
702          } catch (IllegalArgumentException success) {}
703      }
# Line 552 | Line 707 | public class ThreadPoolExecutorSubclassT
707       */
708      public void testConstructor2() {
709          try {
710 <            new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
710 >            new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
711              shouldThrow();
712          } catch (IllegalArgumentException success) {}
713      }
# Line 562 | Line 717 | public class ThreadPoolExecutorSubclassT
717       */
718      public void testConstructor3() {
719          try {
720 <            new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
720 >            new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
721              shouldThrow();
722          } catch (IllegalArgumentException success) {}
723      }
# Line 572 | Line 727 | public class ThreadPoolExecutorSubclassT
727       */
728      public void testConstructor4() {
729          try {
730 <            new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
730 >            new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
731              shouldThrow();
732          } catch (IllegalArgumentException success) {}
733      }
# Line 582 | Line 737 | public class ThreadPoolExecutorSubclassT
737       */
738      public void testConstructor5() {
739          try {
740 <            new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
740 >            new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
741              shouldThrow();
742          } catch (IllegalArgumentException success) {}
743      }
# Line 592 | Line 747 | public class ThreadPoolExecutorSubclassT
747       */
748      public void testConstructorNullPointerException() {
749          try {
750 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
750 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null);
751              shouldThrow();
752          } catch (NullPointerException success) {}
753      }
# Line 604 | Line 759 | public class ThreadPoolExecutorSubclassT
759       */
760      public void testConstructor6() {
761          try {
762 <            new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
762 >            new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
763              shouldThrow();
764          } catch (IllegalArgumentException success) {}
765      }
# Line 614 | Line 769 | public class ThreadPoolExecutorSubclassT
769       */
770      public void testConstructor7() {
771          try {
772 <            new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
772 >            new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
773              shouldThrow();
774          } catch (IllegalArgumentException success) {}
775      }
# Line 624 | Line 779 | public class ThreadPoolExecutorSubclassT
779       */
780      public void testConstructor8() {
781          try {
782 <            new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
782 >            new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
783              shouldThrow();
784          } catch (IllegalArgumentException success) {}
785      }
# Line 634 | Line 789 | public class ThreadPoolExecutorSubclassT
789       */
790      public void testConstructor9() {
791          try {
792 <            new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
792 >            new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
793              shouldThrow();
794          } catch (IllegalArgumentException success) {}
795      }
# Line 644 | Line 799 | public class ThreadPoolExecutorSubclassT
799       */
800      public void testConstructor10() {
801          try {
802 <            new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
802 >            new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
803              shouldThrow();
804          } catch (IllegalArgumentException success) {}
805      }
# Line 654 | Line 809 | public class ThreadPoolExecutorSubclassT
809       */
810      public void testConstructorNullPointerException2() {
811          try {
812 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
812 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory());
813              shouldThrow();
814          } catch (NullPointerException success) {}
815      }
# Line 665 | Line 820 | public class ThreadPoolExecutorSubclassT
820      public void testConstructorNullPointerException3() {
821          try {
822              ThreadFactory f = null;
823 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
823 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
824              shouldThrow();
825          } catch (NullPointerException success) {}
826      }
# Line 676 | Line 831 | public class ThreadPoolExecutorSubclassT
831       */
832      public void testConstructor11() {
833          try {
834 <            new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
834 >            new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
835              shouldThrow();
836          } catch (IllegalArgumentException success) {}
837      }
# Line 686 | Line 841 | public class ThreadPoolExecutorSubclassT
841       */
842      public void testConstructor12() {
843          try {
844 <            new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
844 >            new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
845              shouldThrow();
846          } catch (IllegalArgumentException success) {}
847      }
# Line 696 | Line 851 | public class ThreadPoolExecutorSubclassT
851       */
852      public void testConstructor13() {
853          try {
854 <            new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
854 >            new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
855              shouldThrow();
856          } catch (IllegalArgumentException success) {}
857      }
# Line 706 | Line 861 | public class ThreadPoolExecutorSubclassT
861       */
862      public void testConstructor14() {
863          try {
864 <            new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
864 >            new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
865              shouldThrow();
866          } catch (IllegalArgumentException success) {}
867      }
# Line 716 | Line 871 | public class ThreadPoolExecutorSubclassT
871       */
872      public void testConstructor15() {
873          try {
874 <            new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
874 >            new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
875              shouldThrow();
876          } catch (IllegalArgumentException success) {}
877      }
# Line 726 | Line 881 | public class ThreadPoolExecutorSubclassT
881       */
882      public void testConstructorNullPointerException4() {
883          try {
884 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
884 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler());
885              shouldThrow();
886          } catch (NullPointerException success) {}
887      }
# Line 737 | Line 892 | public class ThreadPoolExecutorSubclassT
892      public void testConstructorNullPointerException5() {
893          try {
894              RejectedExecutionHandler r = null;
895 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
895 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
896              shouldThrow();
897          } catch (NullPointerException success) {}
898      }
# Line 748 | Line 903 | public class ThreadPoolExecutorSubclassT
903       */
904      public void testConstructor16() {
905          try {
906 <            new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
906 >            new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
907              shouldThrow();
908          } catch (IllegalArgumentException success) {}
909      }
# Line 758 | Line 913 | public class ThreadPoolExecutorSubclassT
913       */
914      public void testConstructor17() {
915          try {
916 <            new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
916 >            new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
917              shouldThrow();
918          } catch (IllegalArgumentException success) {}
919      }
# Line 768 | Line 923 | public class ThreadPoolExecutorSubclassT
923       */
924      public void testConstructor18() {
925          try {
926 <            new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
926 >            new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
927              shouldThrow();
928          } catch (IllegalArgumentException success) {}
929      }
# Line 778 | Line 933 | public class ThreadPoolExecutorSubclassT
933       */
934      public void testConstructor19() {
935          try {
936 <            new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
936 >            new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
937              shouldThrow();
938          } catch (IllegalArgumentException success) {}
939      }
# Line 788 | Line 943 | public class ThreadPoolExecutorSubclassT
943       */
944      public void testConstructor20() {
945          try {
946 <            new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
946 >            new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
947              shouldThrow();
948          } catch (IllegalArgumentException success) {}
949      }
950  
951      /**
952 <     * Constructor throws if workQueue is set to null
952 >     * Constructor throws if workQueue is null
953       */
954      public void testConstructorNullPointerException6() {
955          try {
956 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
956 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
957              shouldThrow();
958          } catch (NullPointerException success) {}
959      }
960  
961      /**
962 <     * Constructor throws if handler is set to null
962 >     * Constructor throws if handler is null
963       */
964      public void testConstructorNullPointerException7() {
965          try {
966              RejectedExecutionHandler r = null;
967 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
967 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
968              shouldThrow();
969          } catch (NullPointerException success) {}
970      }
971  
972      /**
973 <     * Constructor throws if ThreadFactory is set top null
973 >     * Constructor throws if ThreadFactory is null
974       */
975      public void testConstructorNullPointerException8() {
976          try {
977 <            ThreadFactory f = null;
978 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
977 >            new CustomTPE(1, 2,
978 >                          LONG_DELAY_MS, MILLISECONDS,
979 >                          new ArrayBlockingQueue<Runnable>(10),
980 >                          (ThreadFactory) null,
981 >                          new NoOpREHandler());
982              shouldThrow();
983          } catch (NullPointerException success) {}
984      }
985  
986  
987      /**
988 <     *  execute throws RejectedExecutionException
831 <     *  if saturated.
988 >     * execute throws RejectedExecutionException if saturated.
989       */
990      public void testSaturatedExecute() {
991 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
992 <        try {
993 <
994 <            for (int i = 0; i < 5; ++i) {
995 <                p.execute(new MediumRunnable());
991 >        ThreadPoolExecutor p =
992 >            new CustomTPE(1, 1,
993 >                          LONG_DELAY_MS, MILLISECONDS,
994 >                          new ArrayBlockingQueue<Runnable>(1));
995 >        final CountDownLatch done = new CountDownLatch(1);
996 >        try {
997 >            Runnable task = new CheckedRunnable() {
998 >                public void realRun() throws InterruptedException {
999 >                    done.await();
1000 >                }};
1001 >            for (int i = 0; i < 2; ++i)
1002 >                p.execute(task);
1003 >            for (int i = 0; i < 2; ++i) {
1004 >                try {
1005 >                    p.execute(task);
1006 >                    shouldThrow();
1007 >                } catch (RejectedExecutionException success) {}
1008 >                assertTrue(p.getTaskCount() <= 2);
1009              }
1010 <            shouldThrow();
1011 <        } catch (RejectedExecutionException success) {}
1012 <        joinPool(p);
1010 >        } finally {
1011 >            done.countDown();
1012 >            joinPool(p);
1013 >        }
1014      }
1015  
1016      /**
1017 <     *  executor using CallerRunsPolicy runs task if saturated.
1017 >     * executor using CallerRunsPolicy runs task if saturated.
1018       */
1019      public void testSaturatedExecute2() {
1020          RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy();
1021 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1021 >        ThreadPoolExecutor p = new CustomTPE(1, 1,
1022 >                                             LONG_DELAY_MS, MILLISECONDS,
1023 >                                             new ArrayBlockingQueue<Runnable>(1),
1024 >                                             h);
1025          try {
852
1026              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
1027 <            for (int i = 0; i < 5; ++i) {
1027 >            for (int i = 0; i < tasks.length; ++i)
1028                  tasks[i] = new TrackedNoOpRunnable();
856            }
1029              TrackedLongRunnable mr = new TrackedLongRunnable();
1030              p.execute(mr);
1031 <            for (int i = 0; i < 5; ++i) {
1031 >            for (int i = 0; i < tasks.length; ++i)
1032                  p.execute(tasks[i]);
1033 <            }
862 <            for (int i = 1; i < 5; ++i) {
1033 >            for (int i = 1; i < tasks.length; ++i)
1034                  assertTrue(tasks[i].done);
864            }
1035              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
1036          } finally {
1037              joinPool(p);
# Line 869 | Line 1039 | public class ThreadPoolExecutorSubclassT
1039      }
1040  
1041      /**
1042 <     *  executor using DiscardPolicy drops task if saturated.
1042 >     * executor using DiscardPolicy drops task if saturated.
1043       */
1044      public void testSaturatedExecute3() {
1045          RejectedExecutionHandler h = new CustomTPE.DiscardPolicy();
1046 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1046 >        ThreadPoolExecutor p =
1047 >            new CustomTPE(1, 1,
1048 >                          LONG_DELAY_MS, MILLISECONDS,
1049 >                          new ArrayBlockingQueue<Runnable>(1),
1050 >                          h);
1051          try {
878
1052              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
1053 <            for (int i = 0; i < 5; ++i) {
1053 >            for (int i = 0; i < tasks.length; ++i)
1054                  tasks[i] = new TrackedNoOpRunnable();
882            }
1055              p.execute(new TrackedLongRunnable());
1056 <            for (int i = 0; i < 5; ++i) {
1057 <                p.execute(tasks[i]);
1058 <            }
1059 <            for (int i = 0; i < 5; ++i) {
888 <                assertFalse(tasks[i].done);
889 <            }
1056 >            for (TrackedNoOpRunnable task : tasks)
1057 >                p.execute(task);
1058 >            for (TrackedNoOpRunnable task : tasks)
1059 >                assertFalse(task.done);
1060              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
1061          } finally {
1062              joinPool(p);
# Line 894 | Line 1064 | public class ThreadPoolExecutorSubclassT
1064      }
1065  
1066      /**
1067 <     *  executor using DiscardOldestPolicy drops oldest task if saturated.
1067 >     * executor using DiscardOldestPolicy drops oldest task if saturated.
1068       */
1069      public void testSaturatedExecute4() {
1070          RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy();
1071 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1071 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1072          try {
1073              p.execute(new TrackedLongRunnable());
1074              TrackedLongRunnable r2 = new TrackedLongRunnable();
# Line 915 | Line 1085 | public class ThreadPoolExecutorSubclassT
1085      }
1086  
1087      /**
1088 <     *  execute throws RejectedExecutionException if shutdown
1088 >     * execute throws RejectedExecutionException if shutdown
1089       */
1090      public void testRejectedExecutionExceptionOnShutdown() {
1091 <        ThreadPoolExecutor tpe =
1092 <            new CustomTPE(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
1093 <        try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1094 <        try {
1095 <            tpe.execute(new NoOpRunnable());
1096 <            shouldThrow();
1097 <        } catch (RejectedExecutionException success) {}
1091 >        ThreadPoolExecutor p =
1092 >            new CustomTPE(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
1093 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
1094 >        try {
1095 >            p.execute(new NoOpRunnable());
1096 >            shouldThrow();
1097 >        } catch (RejectedExecutionException success) {}
1098  
1099 <        joinPool(tpe);
1099 >        joinPool(p);
1100      }
1101  
1102      /**
1103 <     *  execute using CallerRunsPolicy drops task on shutdown
1103 >     * execute using CallerRunsPolicy drops task on shutdown
1104       */
1105      public void testCallerRunsOnShutdown() {
1106          RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy();
1107 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1107 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1108  
1109          try { p.shutdown(); } catch (SecurityException ok) { return; }
1110 <        try {
1110 >        try {
1111              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1112 <            p.execute(r);
1112 >            p.execute(r);
1113              assertFalse(r.done);
1114          } finally {
1115              joinPool(p);
# Line 947 | Line 1117 | public class ThreadPoolExecutorSubclassT
1117      }
1118  
1119      /**
1120 <     *  execute using DiscardPolicy drops task on shutdown
1120 >     * execute using DiscardPolicy drops task on shutdown
1121       */
1122      public void testDiscardOnShutdown() {
1123          RejectedExecutionHandler h = new CustomTPE.DiscardPolicy();
1124 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1124 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1125  
1126          try { p.shutdown(); } catch (SecurityException ok) { return; }
1127 <        try {
1127 >        try {
1128              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1129 <            p.execute(r);
1129 >            p.execute(r);
1130              assertFalse(r.done);
1131          } finally {
1132              joinPool(p);
# Line 965 | Line 1135 | public class ThreadPoolExecutorSubclassT
1135  
1136  
1137      /**
1138 <     *  execute using DiscardOldestPolicy drops task on shutdown
1138 >     * execute using DiscardOldestPolicy drops task on shutdown
1139       */
1140      public void testDiscardOldestOnShutdown() {
1141          RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy();
1142 <        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1142 >        ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h);
1143  
1144          try { p.shutdown(); } catch (SecurityException ok) { return; }
1145 <        try {
1145 >        try {
1146              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1147 <            p.execute(r);
1147 >            p.execute(r);
1148              assertFalse(r.done);
1149          } finally {
1150              joinPool(p);
# Line 983 | Line 1153 | public class ThreadPoolExecutorSubclassT
1153  
1154  
1155      /**
1156 <     *  execute (null) throws NPE
1156 >     * execute(null) throws NPE
1157       */
1158      public void testExecuteNull() {
1159 <        ThreadPoolExecutor tpe = null;
1159 >        ThreadPoolExecutor p = null;
1160          try {
1161 <            tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1162 <            tpe.execute(null);
1161 >            p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1162 >            p.execute(null);
1163              shouldThrow();
1164 <        } catch (NullPointerException success) {}
1164 >        } catch (NullPointerException success) {}
1165  
1166 <        joinPool(tpe);
1166 >        joinPool(p);
1167      }
1168  
1169      /**
1170 <     *  setCorePoolSize of negative value throws IllegalArgumentException
1170 >     * setCorePoolSize of negative value throws IllegalArgumentException
1171       */
1172      public void testCorePoolSizeIllegalArgumentException() {
1173 <        ThreadPoolExecutor tpe =
1174 <            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1175 <        try {
1176 <            tpe.setCorePoolSize(-1);
1177 <            shouldThrow();
1178 <        } catch (IllegalArgumentException success) {
1173 >        ThreadPoolExecutor p =
1174 >            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1175 >        try {
1176 >            p.setCorePoolSize(-1);
1177 >            shouldThrow();
1178 >        } catch (IllegalArgumentException success) {
1179          } finally {
1180 <            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1180 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
1181          }
1182 <        joinPool(tpe);
1182 >        joinPool(p);
1183      }
1184  
1185      /**
1186 <     *  setMaximumPoolSize(int) throws IllegalArgumentException if
1187 <     *  given a value less the core pool size
1186 >     * setMaximumPoolSize(int) throws IllegalArgumentException
1187 >     * if given a value less the core pool size
1188       */
1189      public void testMaximumPoolSizeIllegalArgumentException() {
1190 <        ThreadPoolExecutor tpe = null;
1190 >        ThreadPoolExecutor p =
1191 >            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1192          try {
1193 <            tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1023 <        } catch (Exception e) {}
1024 <        try {
1025 <            tpe.setMaximumPoolSize(1);
1193 >            p.setMaximumPoolSize(1);
1194              shouldThrow();
1195          } catch (IllegalArgumentException success) {
1196          } finally {
1197 <            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1197 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
1198          }
1199 <        joinPool(tpe);
1199 >        joinPool(p);
1200      }
1201  
1202      /**
1203 <     *  setMaximumPoolSize throws IllegalArgumentException
1204 <     *  if given a negative value
1203 >     * setMaximumPoolSize throws IllegalArgumentException
1204 >     * if given a negative value
1205       */
1206      public void testMaximumPoolSizeIllegalArgumentException2() {
1207 <        ThreadPoolExecutor tpe = null;
1207 >        ThreadPoolExecutor p =
1208 >            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1209          try {
1210 <            tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1042 <        } catch (Exception e) {}
1043 <        try {
1044 <            tpe.setMaximumPoolSize(-1);
1210 >            p.setMaximumPoolSize(-1);
1211              shouldThrow();
1212          } catch (IllegalArgumentException success) {
1213          } finally {
1214 <            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1214 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
1215          }
1216 <        joinPool(tpe);
1216 >        joinPool(p);
1217      }
1218  
1219  
1220      /**
1221 <     *  setKeepAliveTime  throws IllegalArgumentException
1222 <     *  when given a negative value
1221 >     * setKeepAliveTime throws IllegalArgumentException
1222 >     * when given a negative value
1223       */
1224      public void testKeepAliveTimeIllegalArgumentException() {
1225 <        ThreadPoolExecutor tpe = null;
1226 <        try {
1061 <            tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1062 <        } catch (Exception e) {}
1225 >        ThreadPoolExecutor p =
1226 >            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1227  
1228 <        try {
1229 <            tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS);
1228 >        try {
1229 >            p.setKeepAliveTime(-1,MILLISECONDS);
1230              shouldThrow();
1231          } catch (IllegalArgumentException success) {
1232          } finally {
1233 <            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1233 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
1234          }
1235 <        joinPool(tpe);
1235 >        joinPool(p);
1236      }
1237  
1238      /**
1239       * terminated() is called on termination
1240       */
1241      public void testTerminated() {
1242 <        CustomTPE tpe = new CustomTPE();
1243 <        try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1244 <        assertTrue(tpe.terminatedCalled);
1245 <        joinPool(tpe);
1242 >        CustomTPE p = new CustomTPE();
1243 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
1244 >        assertTrue(p.terminatedCalled);
1245 >        joinPool(p);
1246      }
1247  
1248      /**
1249       * beforeExecute and afterExecute are called when executing task
1250       */
1251      public void testBeforeAfter() throws InterruptedException {
1252 <        CustomTPE tpe = new CustomTPE();
1252 >        CustomTPE p = new CustomTPE();
1253          try {
1254              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1255 <            tpe.execute(r);
1255 >            p.execute(r);
1256              Thread.sleep(SHORT_DELAY_MS);
1257              assertTrue(r.done);
1258 <            assertTrue(tpe.beforeCalled);
1259 <            assertTrue(tpe.afterCalled);
1260 <            try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1258 >            assertTrue(p.beforeCalled);
1259 >            assertTrue(p.afterCalled);
1260 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
1261          } finally {
1262 <            joinPool(tpe);
1262 >            joinPool(p);
1263          }
1264      }
1265  
# Line 1103 | Line 1267 | public class ThreadPoolExecutorSubclassT
1267       * completed submit of callable returns result
1268       */
1269      public void testSubmitCallable() throws Exception {
1270 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1270 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1271          try {
1272              Future<String> future = e.submit(new StringTask());
1273              String result = future.get();
# Line 1117 | Line 1281 | public class ThreadPoolExecutorSubclassT
1281       * completed submit of runnable returns successfully
1282       */
1283      public void testSubmitRunnable() throws Exception {
1284 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1284 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1285          try {
1286              Future<?> future = e.submit(new NoOpRunnable());
1287              future.get();
# Line 1131 | Line 1295 | public class ThreadPoolExecutorSubclassT
1295       * completed submit of (runnable, result) returns result
1296       */
1297      public void testSubmitRunnable2() throws Exception {
1298 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1298 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1299          try {
1300              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1301              String result = future.get();
# Line 1146 | Line 1310 | public class ThreadPoolExecutorSubclassT
1310       * invokeAny(null) throws NPE
1311       */
1312      public void testInvokeAny1() throws Exception {
1313 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1313 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1314          try {
1315              e.invokeAny(null);
1316              shouldThrow();
# Line 1160 | Line 1324 | public class ThreadPoolExecutorSubclassT
1324       * invokeAny(empty collection) throws IAE
1325       */
1326      public void testInvokeAny2() throws Exception {
1327 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1327 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1328          try {
1329              e.invokeAny(new ArrayList<Callable<String>>());
1330              shouldThrow();
# Line 1174 | Line 1338 | public class ThreadPoolExecutorSubclassT
1338       * invokeAny(c) throws NPE if c has null elements
1339       */
1340      public void testInvokeAny3() throws Exception {
1341 <        final CountDownLatch latch = new CountDownLatch(1);
1342 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1341 >        CountDownLatch latch = new CountDownLatch(1);
1342 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1343 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1344 >        l.add(latchAwaitingStringTask(latch));
1345 >        l.add(null);
1346          try {
1180            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1181            l.add(new CheckedCallable<String>() {
1182                      public String realCall() throws InterruptedException {
1183                          latch.await();
1184                          return TEST_STRING;
1185                      }});
1186            l.add(null);
1347              e.invokeAny(l);
1348              shouldThrow();
1349          } catch (NullPointerException success) {
# Line 1197 | Line 1357 | public class ThreadPoolExecutorSubclassT
1357       * invokeAny(c) throws ExecutionException if no task completes
1358       */
1359      public void testInvokeAny4() throws Exception {
1360 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1360 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1361 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1362 >        l.add(new NPETask());
1363          try {
1202            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1203            l.add(new NPETask());
1364              e.invokeAny(l);
1365              shouldThrow();
1366          } catch (ExecutionException success) {
1367 +            assertTrue(success.getCause() instanceof NullPointerException);
1368          } finally {
1369              joinPool(e);
1370          }
# Line 1213 | Line 1374 | public class ThreadPoolExecutorSubclassT
1374       * invokeAny(c) returns result of some task
1375       */
1376      public void testInvokeAny5() throws Exception {
1377 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1377 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1378          try {
1379 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1379 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1380              l.add(new StringTask());
1381              l.add(new StringTask());
1382              String result = e.invokeAny(l);
# Line 1229 | Line 1390 | public class ThreadPoolExecutorSubclassT
1390       * invokeAll(null) throws NPE
1391       */
1392      public void testInvokeAll1() throws Exception {
1393 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1393 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1394          try {
1395              e.invokeAll(null);
1396              shouldThrow();
# Line 1243 | Line 1404 | public class ThreadPoolExecutorSubclassT
1404       * invokeAll(empty collection) returns empty collection
1405       */
1406      public void testInvokeAll2() throws Exception {
1407 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1407 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1408          try {
1409              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1410              assertTrue(r.isEmpty());
# Line 1256 | Line 1417 | public class ThreadPoolExecutorSubclassT
1417       * invokeAll(c) throws NPE if c has null elements
1418       */
1419      public void testInvokeAll3() throws Exception {
1420 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1420 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1421 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1422 >        l.add(new StringTask());
1423 >        l.add(null);
1424          try {
1261            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1262            l.add(new StringTask());
1263            l.add(null);
1425              e.invokeAll(l);
1426              shouldThrow();
1427          } catch (NullPointerException success) {
# Line 1273 | Line 1434 | public class ThreadPoolExecutorSubclassT
1434       * get of element of invokeAll(c) throws exception on failed task
1435       */
1436      public void testInvokeAll4() throws Exception {
1437 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1437 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1438 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1439 >        l.add(new NPETask());
1440 >        List<Future<String>> futures = e.invokeAll(l);
1441 >        assertEquals(1, futures.size());
1442          try {
1443 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1279 <            l.add(new NPETask());
1280 <            List<Future<String>> result = e.invokeAll(l);
1281 <            assertEquals(1, result.size());
1282 <            for (Future<String> future : result)
1283 <                future.get();
1443 >            futures.get(0).get();
1444              shouldThrow();
1445          } catch (ExecutionException success) {
1446 +            assertTrue(success.getCause() instanceof NullPointerException);
1447          } finally {
1448              joinPool(e);
1449          }
# Line 1292 | Line 1453 | public class ThreadPoolExecutorSubclassT
1453       * invokeAll(c) returns results of all completed tasks
1454       */
1455      public void testInvokeAll5() throws Exception {
1456 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1456 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1457          try {
1458 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1458 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1459              l.add(new StringTask());
1460              l.add(new StringTask());
1461 <            List<Future<String>> result = e.invokeAll(l);
1462 <            assertEquals(2, result.size());
1463 <            for (Future<String> future : result)
1461 >            List<Future<String>> futures = e.invokeAll(l);
1462 >            assertEquals(2, futures.size());
1463 >            for (Future<String> future : futures)
1464                  assertSame(TEST_STRING, future.get());
1465          } finally {
1466              joinPool(e);
# Line 1312 | Line 1473 | public class ThreadPoolExecutorSubclassT
1473       * timed invokeAny(null) throws NPE
1474       */
1475      public void testTimedInvokeAny1() throws Exception {
1476 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1476 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1477          try {
1478 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1478 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
1479              shouldThrow();
1480          } catch (NullPointerException success) {
1481          } finally {
# Line 1326 | Line 1487 | public class ThreadPoolExecutorSubclassT
1487       * timed invokeAny(,,null) throws NPE
1488       */
1489      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1490 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1490 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1491 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1492 >        l.add(new StringTask());
1493          try {
1331            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1332            l.add(new StringTask());
1494              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1495              shouldThrow();
1496          } catch (NullPointerException success) {
# Line 1342 | Line 1503 | public class ThreadPoolExecutorSubclassT
1503       * timed invokeAny(empty collection) throws IAE
1504       */
1505      public void testTimedInvokeAny2() throws Exception {
1506 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1506 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1507          try {
1508 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1508 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1509              shouldThrow();
1510          } catch (IllegalArgumentException success) {
1511          } finally {
# Line 1356 | Line 1517 | public class ThreadPoolExecutorSubclassT
1517       * timed invokeAny(c) throws NPE if c has null elements
1518       */
1519      public void testTimedInvokeAny3() throws Exception {
1520 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1520 >        CountDownLatch latch = new CountDownLatch(1);
1521 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1522 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1523 >        l.add(latchAwaitingStringTask(latch));
1524 >        l.add(null);
1525          try {
1526 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1362 <            l.add(new StringTask());
1363 <            l.add(null);
1364 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1526 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1527              shouldThrow();
1528          } catch (NullPointerException success) {
1529          } finally {
1530 +            latch.countDown();
1531              joinPool(e);
1532          }
1533      }
# Line 1373 | Line 1536 | public class ThreadPoolExecutorSubclassT
1536       * timed invokeAny(c) throws ExecutionException if no task completes
1537       */
1538      public void testTimedInvokeAny4() throws Exception {
1539 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1539 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1540 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1541 >        l.add(new NPETask());
1542          try {
1543 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1379 <            l.add(new NPETask());
1380 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1543 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1544              shouldThrow();
1545          } catch (ExecutionException success) {
1546 +            assertTrue(success.getCause() instanceof NullPointerException);
1547          } finally {
1548              joinPool(e);
1549          }
# Line 1389 | Line 1553 | public class ThreadPoolExecutorSubclassT
1553       * timed invokeAny(c) returns result of some task
1554       */
1555      public void testTimedInvokeAny5() throws Exception {
1556 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1556 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1557          try {
1558 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1558 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1559              l.add(new StringTask());
1560              l.add(new StringTask());
1561 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1561 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1562              assertSame(TEST_STRING, result);
1563          } finally {
1564              joinPool(e);
# Line 1405 | Line 1569 | public class ThreadPoolExecutorSubclassT
1569       * timed invokeAll(null) throws NPE
1570       */
1571      public void testTimedInvokeAll1() throws Exception {
1572 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1572 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1573          try {
1574 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1574 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1575              shouldThrow();
1576          } catch (NullPointerException success) {
1577          } finally {
# Line 1419 | Line 1583 | public class ThreadPoolExecutorSubclassT
1583       * timed invokeAll(,,null) throws NPE
1584       */
1585      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1586 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1586 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1587 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1588 >        l.add(new StringTask());
1589          try {
1424            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1425            l.add(new StringTask());
1590              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1591              shouldThrow();
1592          } catch (NullPointerException success) {
# Line 1435 | Line 1599 | public class ThreadPoolExecutorSubclassT
1599       * timed invokeAll(empty collection) returns empty collection
1600       */
1601      public void testTimedInvokeAll2() throws Exception {
1602 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1602 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1603          try {
1604 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1604 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1605              assertTrue(r.isEmpty());
1606          } finally {
1607              joinPool(e);
# Line 1448 | Line 1612 | public class ThreadPoolExecutorSubclassT
1612       * timed invokeAll(c) throws NPE if c has null elements
1613       */
1614      public void testTimedInvokeAll3() throws Exception {
1615 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1615 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1616 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1617 >        l.add(new StringTask());
1618 >        l.add(null);
1619          try {
1620 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1454 <            l.add(new StringTask());
1455 <            l.add(null);
1456 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1620 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1621              shouldThrow();
1622          } catch (NullPointerException success) {
1623          } finally {
# Line 1465 | Line 1629 | public class ThreadPoolExecutorSubclassT
1629       * get of element of invokeAll(c) throws exception on failed task
1630       */
1631      public void testTimedInvokeAll4() throws Exception {
1632 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1632 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1633 >        List<Callable<String>> l = new ArrayList<Callable<String>>();
1634 >        l.add(new NPETask());
1635 >        List<Future<String>> futures =
1636 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1637 >        assertEquals(1, futures.size());
1638          try {
1639 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1471 <            l.add(new NPETask());
1472 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1473 <            assertEquals(1, result.size());
1474 <            for (Future<String> future : result)
1475 <                future.get();
1639 >            futures.get(0).get();
1640              shouldThrow();
1641          } catch (ExecutionException success) {
1642              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1485 | Line 1649 | public class ThreadPoolExecutorSubclassT
1649       * timed invokeAll(c) returns results of all completed tasks
1650       */
1651      public void testTimedInvokeAll5() throws Exception {
1652 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1652 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1653          try {
1654 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1654 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1655              l.add(new StringTask());
1656              l.add(new StringTask());
1657 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1658 <            assertEquals(2, result.size());
1659 <            for (Future<String> future : result)
1657 >            List<Future<String>> futures =
1658 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1659 >            assertEquals(2, futures.size());
1660 >            for (Future<String> future : futures)
1661                  assertSame(TEST_STRING, future.get());
1497        } catch (ExecutionException success) {
1662          } finally {
1663              joinPool(e);
1664          }
# Line 1504 | Line 1668 | public class ThreadPoolExecutorSubclassT
1668       * timed invokeAll(c) cancels tasks not completed by timeout
1669       */
1670      public void testTimedInvokeAll6() throws Exception {
1671 <        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1671 >        ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1672          try {
1673 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1673 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1674              l.add(new StringTask());
1675              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1676              l.add(new StringTask());
1677 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1678 <            assertEquals(3, result.size());
1679 <            Iterator<Future<String>> it = result.iterator();
1677 >            List<Future<String>> futures =
1678 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1679 >            assertEquals(3, futures.size());
1680 >            Iterator<Future<String>> it = futures.iterator();
1681              Future<String> f1 = it.next();
1682              Future<String> f2 = it.next();
1683              Future<String> f3 = it.next();
# Line 1531 | Line 1696 | public class ThreadPoolExecutorSubclassT
1696       * thread factory fails to create more
1697       */
1698      public void testFailingThreadFactory() throws InterruptedException {
1699 <        ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1700 <        try {
1701 <            for (int k = 0; k < 100; ++k) {
1702 <                e.execute(new NoOpRunnable());
1703 <            }
1704 <            Thread.sleep(LONG_DELAY_MS);
1699 >        final ExecutorService e =
1700 >            new CustomTPE(100, 100,
1701 >                          LONG_DELAY_MS, MILLISECONDS,
1702 >                          new LinkedBlockingQueue<Runnable>(),
1703 >                          new FailingThreadFactory());
1704 >        try {
1705 >            final int TASKS = 100;
1706 >            final CountDownLatch done = new CountDownLatch(TASKS);
1707 >            for (int k = 0; k < TASKS; ++k)
1708 >                e.execute(new CheckedRunnable() {
1709 >                    public void realRun() {
1710 >                        done.countDown();
1711 >                    }});
1712 >            assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
1713          } finally {
1714              joinPool(e);
1715          }
# Line 1546 | Line 1719 | public class ThreadPoolExecutorSubclassT
1719       * allowsCoreThreadTimeOut is by default false.
1720       */
1721      public void testAllowsCoreThreadTimeOut() {
1722 <        ThreadPoolExecutor tpe = new CustomTPE(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1723 <        assertFalse(tpe.allowsCoreThreadTimeOut());
1724 <        joinPool(tpe);
1722 >        ThreadPoolExecutor p = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1723 >        assertFalse(p.allowsCoreThreadTimeOut());
1724 >        joinPool(p);
1725      }
1726  
1727      /**
1728       * allowCoreThreadTimeOut(true) causes idle threads to time out
1729       */
1730 <    public void testAllowCoreThreadTimeOut_true() throws InterruptedException {
1731 <        ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1732 <        tpe.allowCoreThreadTimeOut(true);
1733 <        tpe.execute(new NoOpRunnable());
1734 <        try {
1735 <            Thread.sleep(MEDIUM_DELAY_MS);
1736 <            assertEquals(0, tpe.getPoolSize());
1730 >    public void testAllowCoreThreadTimeOut_true() throws Exception {
1731 >        final ThreadPoolExecutor p =
1732 >            new CustomTPE(2, 10,
1733 >                          SHORT_DELAY_MS, MILLISECONDS,
1734 >                          new ArrayBlockingQueue<Runnable>(10));
1735 >        final CountDownLatch threadStarted = new CountDownLatch(1);
1736 >        try {
1737 >            p.allowCoreThreadTimeOut(true);
1738 >            p.execute(new CheckedRunnable() {
1739 >                public void realRun() throws InterruptedException {
1740 >                    threadStarted.countDown();
1741 >                    assertEquals(1, p.getPoolSize());
1742 >                }});
1743 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
1744 >            for (int i = 0; i < (MEDIUM_DELAY_MS/10); i++) {
1745 >                if (p.getPoolSize() == 0)
1746 >                    break;
1747 >                Thread.sleep(10);
1748 >            }
1749 >            assertEquals(0, p.getPoolSize());
1750          } finally {
1751 <            joinPool(tpe);
1751 >            joinPool(p);
1752          }
1753      }
1754  
1755      /**
1756       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1757       */
1758 <    public void testAllowCoreThreadTimeOut_false() throws InterruptedException {
1759 <        ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1760 <        tpe.allowCoreThreadTimeOut(false);
1761 <        tpe.execute(new NoOpRunnable());
1762 <        try {
1763 <            Thread.sleep(MEDIUM_DELAY_MS);
1764 <            assertTrue(tpe.getPoolSize() >= 1);
1758 >    public void testAllowCoreThreadTimeOut_false() throws Exception {
1759 >        final ThreadPoolExecutor p =
1760 >            new CustomTPE(2, 10,
1761 >                          SHORT_DELAY_MS, MILLISECONDS,
1762 >                          new ArrayBlockingQueue<Runnable>(10));
1763 >        final CountDownLatch threadStarted = new CountDownLatch(1);
1764 >        try {
1765 >            p.allowCoreThreadTimeOut(false);
1766 >            p.execute(new CheckedRunnable() {
1767 >                public void realRun() throws InterruptedException {
1768 >                    threadStarted.countDown();
1769 >                    assertTrue(p.getPoolSize() >= 1);
1770 >                }});
1771 >            Thread.sleep(SMALL_DELAY_MS);
1772 >            assertTrue(p.getPoolSize() >= 1);
1773          } finally {
1774 <            joinPool(tpe);
1774 >            joinPool(p);
1775          }
1776      }
1777  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines