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

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.79 by jsr166, Sun Oct 4 02:15:08 2015 UTC vs.
Revision 1.83 by jsr166, Sun Oct 4 02:29:46 2015 UTC

# Line 87 | Line 87 | public class ThreadPoolExecutorTest exte
87              new ThreadPoolExecutor(1, 1,
88                                     LONG_DELAY_MS, MILLISECONDS,
89                                     new ArrayBlockingQueue<Runnable>(10));
90 <        final CountDownLatch done = new CountDownLatch(1);
91 <        final Runnable task = new CheckedRunnable() {
92 <            public void realRun() {
93 <                done.countDown();
94 <            }};
95 <        try {
90 >        try (PoolCleaner cleaner = cleaner(p)) {
91 >            final CountDownLatch done = new CountDownLatch(1);
92 >            final Runnable task = new CheckedRunnable() {
93 >                public void realRun() { done.countDown(); }};
94              p.execute(task);
95 <            assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
98 <        } finally {
99 <            joinPool(p);
95 >            assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
96          }
97      }
98  
# Line 109 | Line 105 | public class ThreadPoolExecutorTest exte
105              new ThreadPoolExecutor(2, 2,
106                                     LONG_DELAY_MS, MILLISECONDS,
107                                     new ArrayBlockingQueue<Runnable>(10));
108 <        final CountDownLatch threadStarted = new CountDownLatch(1);
109 <        final CountDownLatch done = new CountDownLatch(1);
110 <        try {
108 >        try (PoolCleaner cleaner = cleaner(p)) {
109 >            final CountDownLatch threadStarted = new CountDownLatch(1);
110 >            final CountDownLatch done = new CountDownLatch(1);
111              assertEquals(0, p.getActiveCount());
112              p.execute(new CheckedRunnable() {
113                  public void realRun() throws InterruptedException {
# Line 121 | Line 117 | public class ThreadPoolExecutorTest exte
117                  }});
118              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
119              assertEquals(1, p.getActiveCount());
124        } finally {
120              done.countDown();
126            joinPool(p);
121          }
122      }
123  
# Line 408 | Line 402 | public class ThreadPoolExecutorTest exte
402              new ThreadPoolExecutor(1, 1,
403                                     LONG_DELAY_MS, MILLISECONDS,
404                                     new ArrayBlockingQueue<Runnable>(10));
405 <        final CountDownLatch threadStarted = new CountDownLatch(1);
406 <        final CountDownLatch done = new CountDownLatch(1);
407 <        try {
405 >        try (PoolCleaner cleaner = cleaner(p)) {
406 >            final CountDownLatch threadStarted = new CountDownLatch(1);
407 >            final CountDownLatch done = new CountDownLatch(1);
408              assertEquals(0, p.getTaskCount());
409              p.execute(new CheckedRunnable() {
410                  public void realRun() throws InterruptedException {
# Line 420 | Line 414 | public class ThreadPoolExecutorTest exte
414                  }});
415              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
416              assertEquals(1, p.getTaskCount());
423        } finally {
417              done.countDown();
425            joinPool(p);
418          }
419      }
420  
# Line 434 | Line 426 | public class ThreadPoolExecutorTest exte
426              new ThreadPoolExecutor(1, 1,
427                                     LONG_DELAY_MS, MILLISECONDS,
428                                     new ArrayBlockingQueue<Runnable>(10));
429 <        assertFalse(p.isShutdown());
430 <        try { p.shutdown(); } catch (SecurityException ok) { return; }
431 <        assertTrue(p.isShutdown());
432 <        joinPool(p);
429 >        try (PoolCleaner cleaner = cleaner(p)) {
430 >            assertFalse(p.isShutdown());
431 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
432 >            assertTrue(p.isShutdown());
433 >        }
434      }
435  
436      /**
# Line 478 | Line 471 | public class ThreadPoolExecutorTest exte
471              new ThreadPoolExecutor(1, 1,
472                                     LONG_DELAY_MS, MILLISECONDS,
473                                     new ArrayBlockingQueue<Runnable>(10));
474 <        final CountDownLatch threadStarted = new CountDownLatch(1);
475 <        final CountDownLatch done = new CountDownLatch(1);
476 <        assertFalse(p.isTerminated());
477 <        try {
474 >        try (PoolCleaner cleaner = cleaner(p)) {
475 >            final CountDownLatch threadStarted = new CountDownLatch(1);
476 >            final CountDownLatch done = new CountDownLatch(1);
477 >            assertFalse(p.isTerminating());
478              p.execute(new CheckedRunnable() {
479                  public void realRun() throws InterruptedException {
480 <                    assertFalse(p.isTerminated());
480 >                    assertFalse(p.isTerminating());
481                      threadStarted.countDown();
482                      done.await();
483                  }});
484              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
485              assertFalse(p.isTerminating());
486              done.countDown();
494        } finally {
487              try { p.shutdown(); } catch (SecurityException ok) { return; }
488 +            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
489 +            assertTrue(p.isTerminated());
490 +            assertFalse(p.isTerminating());
491          }
497        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
498        assertTrue(p.isTerminated());
492      }
493  
494      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines