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

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.61 by jsr166, Sun Oct 4 02:15:08 2015 UTC vs.
Revision 1.62 by jsr166, Sun Oct 4 08:07:31 2015 UTC

# Line 43 | Line 43 | public class ScheduledExecutorTest exten
43       */
44      public void testExecute() throws InterruptedException {
45          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
46 <        final CountDownLatch done = new CountDownLatch(1);
47 <        final Runnable task = new CheckedRunnable() {
48 <            public void realRun() {
49 <                done.countDown();
50 <            }};
51 <        try {
46 >        try (PoolCleaner cleaner = cleaner(p)) {
47 >            final CountDownLatch done = new CountDownLatch(1);
48 >            final Runnable task = new CheckedRunnable() {
49 >                public void realRun() { done.countDown(); }};
50              p.execute(task);
51              assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
54        } finally {
55            joinPool(p);
52          }
53      }
54  
# Line 61 | Line 57 | public class ScheduledExecutorTest exten
57       */
58      public void testSchedule1() throws Exception {
59          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
60 <        final long startTime = System.nanoTime();
61 <        final CountDownLatch done = new CountDownLatch(1);
62 <        try {
60 >        try (PoolCleaner cleaner = cleaner(p)) {
61 >            final long startTime = System.nanoTime();
62 >            final CountDownLatch done = new CountDownLatch(1);
63              Callable task = new CheckedCallable<Boolean>() {
64                  public Boolean realCall() {
65                      done.countDown();
# Line 74 | Line 70 | public class ScheduledExecutorTest exten
70              assertSame(Boolean.TRUE, f.get());
71              assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
72              assertTrue(done.await(0L, MILLISECONDS));
77        } finally {
78            joinPool(p);
73          }
74      }
75  
# Line 84 | Line 78 | public class ScheduledExecutorTest exten
78       */
79      public void testSchedule3() throws Exception {
80          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
81 <        final long startTime = System.nanoTime();
82 <        final CountDownLatch done = new CountDownLatch(1);
83 <        try {
81 >        try (PoolCleaner cleaner = cleaner(p)) {
82 >            final long startTime = System.nanoTime();
83 >            final CountDownLatch done = new CountDownLatch(1);
84              Runnable task = new CheckedRunnable() {
85                  public void realRun() {
86                      done.countDown();
# Line 96 | Line 90 | public class ScheduledExecutorTest exten
90              await(done);
91              assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
92              assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
99        } finally {
100            joinPool(p);
93          }
94      }
95  
# Line 106 | Line 98 | public class ScheduledExecutorTest exten
98       */
99      public void testSchedule4() throws Exception {
100          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
101 <        final long startTime = System.nanoTime();
102 <        final CountDownLatch done = new CountDownLatch(1);
103 <        try {
101 >        try (PoolCleaner cleaner = cleaner(p)) {
102 >            final long startTime = System.nanoTime();
103 >            final CountDownLatch done = new CountDownLatch(1);
104              Runnable task = new CheckedRunnable() {
105                  public void realRun() {
106                      done.countDown();
# Line 120 | Line 112 | public class ScheduledExecutorTest exten
112              await(done);
113              assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
114              f.cancel(true);
123        } finally {
124            joinPool(p);
115          }
116      }
117  
# Line 130 | Line 120 | public class ScheduledExecutorTest exten
120       */
121      public void testSchedule5() throws Exception {
122          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
123 <        final long startTime = System.nanoTime();
124 <        final CountDownLatch done = new CountDownLatch(1);
125 <        try {
123 >        try (PoolCleaner cleaner = cleaner(p)) {
124 >            final long startTime = System.nanoTime();
125 >            final CountDownLatch done = new CountDownLatch(1);
126              Runnable task = new CheckedRunnable() {
127                  public void realRun() {
128                      done.countDown();
# Line 144 | Line 134 | public class ScheduledExecutorTest exten
134              await(done);
135              assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
136              f.cancel(true);
147        } finally {
148            joinPool(p);
137          }
138      }
139  
# Line 159 | Line 147 | public class ScheduledExecutorTest exten
147       */
148      public void testFixedRateSequence() throws InterruptedException {
149          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
150 <        try {
150 >        try (PoolCleaner cleaner = cleaner(p)) {
151              for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
152                  long startTime = System.nanoTime();
153                  int cycles = 10;
# Line 177 | Line 165 | public class ScheduledExecutorTest exten
165                      return;
166              }
167              throw new AssertionError("unexpected execution rate");
180        } finally {
181            joinPool(p);
168          }
169      }
170  
# Line 187 | Line 173 | public class ScheduledExecutorTest exten
173       */
174      public void testFixedDelaySequence() throws InterruptedException {
175          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
176 <        try {
176 >        try (PoolCleaner cleaner = cleaner(p)) {
177              for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
178                  long startTime = System.nanoTime();
179                  int cycles = 10;
# Line 205 | Line 191 | public class ScheduledExecutorTest exten
191                      return;
192              }
193              throw new AssertionError("unexpected execution rate");
208        } finally {
209            joinPool(p);
194          }
195      }
196  
# Line 214 | Line 198 | public class ScheduledExecutorTest exten
198       * execute(null) throws NPE
199       */
200      public void testExecuteNull() throws InterruptedException {
201 <        ScheduledThreadPoolExecutor se = null;
202 <        try {
203 <            se = new ScheduledThreadPoolExecutor(1);
204 <            se.execute(null);
205 <            shouldThrow();
206 <        } catch (NullPointerException success) {}
207 <
224 <        joinPool(se);
201 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
202 >        try (PoolCleaner cleaner = cleaner(p)) {
203 >            try {
204 >                p.execute(null);
205 >                shouldThrow();
206 >            } catch (NullPointerException success) {}
207 >        }
208      }
209  
210      /**
211       * schedule(null) throws NPE
212       */
213      public void testScheduleNull() throws InterruptedException {
214 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
215 <        try {
216 <            TrackedCallable callable = null;
217 <            Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
218 <            shouldThrow();
219 <        } catch (NullPointerException success) {}
220 <        joinPool(se);
214 >        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
215 >        try (PoolCleaner cleaner = cleaner(p)) {
216 >            try {
217 >                TrackedCallable callable = null;
218 >                Future f = p.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
219 >                shouldThrow();
220 >            } catch (NullPointerException success) {}
221 >        }
222      }
223  
224      /**
225       * execute throws RejectedExecutionException if shutdown
226       */
227      public void testSchedule1_RejectedExecutionException() throws InterruptedException {
228 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
229 <        try {
230 <            se.shutdown();
231 <            se.schedule(new NoOpRunnable(),
232 <                        MEDIUM_DELAY_MS, MILLISECONDS);
233 <            shouldThrow();
234 <        } catch (RejectedExecutionException success) {
235 <        } catch (SecurityException ok) {
228 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
229 >        try (PoolCleaner cleaner = cleaner(p)) {
230 >            try {
231 >                p.shutdown();
232 >                p.schedule(new NoOpRunnable(),
233 >                           MEDIUM_DELAY_MS, MILLISECONDS);
234 >                shouldThrow();
235 >            } catch (RejectedExecutionException success) {
236 >            } catch (SecurityException ok) {}
237          }
253
254        joinPool(se);
238      }
239  
240      /**
241       * schedule throws RejectedExecutionException if shutdown
242       */
243      public void testSchedule2_RejectedExecutionException() throws InterruptedException {
244 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
245 <        try {
246 <            se.shutdown();
247 <            se.schedule(new NoOpCallable(),
248 <                        MEDIUM_DELAY_MS, MILLISECONDS);
249 <            shouldThrow();
250 <        } catch (RejectedExecutionException success) {
251 <        } catch (SecurityException ok) {
244 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
245 >        try (PoolCleaner cleaner = cleaner(p)) {
246 >            try {
247 >                p.shutdown();
248 >                p.schedule(new NoOpCallable(),
249 >                           MEDIUM_DELAY_MS, MILLISECONDS);
250 >                shouldThrow();
251 >            } catch (RejectedExecutionException success) {
252 >            } catch (SecurityException ok) {}
253          }
270        joinPool(se);
254      }
255  
256      /**
257       * schedule callable throws RejectedExecutionException if shutdown
258       */
259      public void testSchedule3_RejectedExecutionException() throws InterruptedException {
260 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
261 <        try {
262 <            se.shutdown();
263 <            se.schedule(new NoOpCallable(),
264 <                        MEDIUM_DELAY_MS, MILLISECONDS);
265 <            shouldThrow();
266 <        } catch (RejectedExecutionException success) {
267 <        } catch (SecurityException ok) {
260 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
261 >        try (PoolCleaner cleaner = cleaner(p)) {
262 >            try {
263 >                p.shutdown();
264 >                p.schedule(new NoOpCallable(),
265 >                           MEDIUM_DELAY_MS, MILLISECONDS);
266 >                shouldThrow();
267 >            } catch (RejectedExecutionException success) {
268 >            } catch (SecurityException ok) {}
269          }
286        joinPool(se);
270      }
271  
272      /**
273       * scheduleAtFixedRate throws RejectedExecutionException if shutdown
274       */
275      public void testScheduleAtFixedRate1_RejectedExecutionException() throws InterruptedException {
276 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
277 <        try {
278 <            se.shutdown();
279 <            se.scheduleAtFixedRate(new NoOpRunnable(),
280 <                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
281 <            shouldThrow();
282 <        } catch (RejectedExecutionException success) {
283 <        } catch (SecurityException ok) {
276 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
277 >        try (PoolCleaner cleaner = cleaner(p)) {
278 >            try {
279 >                p.shutdown();
280 >                p.scheduleAtFixedRate(new NoOpRunnable(),
281 >                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
282 >                shouldThrow();
283 >            } catch (RejectedExecutionException success) {
284 >            } catch (SecurityException ok) {}
285          }
302        joinPool(se);
286      }
287  
288      /**
289       * scheduleWithFixedDelay throws RejectedExecutionException if shutdown
290       */
291      public void testScheduleWithFixedDelay1_RejectedExecutionException() throws InterruptedException {
292 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
293 <        try {
294 <            se.shutdown();
295 <            se.scheduleWithFixedDelay(new NoOpRunnable(),
296 <                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
297 <            shouldThrow();
298 <        } catch (RejectedExecutionException success) {
299 <        } catch (SecurityException ok) {
292 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
293 >        try (PoolCleaner cleaner = cleaner(p)) {
294 >            try {
295 >                p.shutdown();
296 >                p.scheduleWithFixedDelay(new NoOpRunnable(),
297 >                                         MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
298 >                shouldThrow();
299 >            } catch (RejectedExecutionException success) {
300 >            } catch (SecurityException ok) {}
301          }
318        joinPool(se);
302      }
303  
304      /**
# Line 324 | Line 307 | public class ScheduledExecutorTest exten
307       */
308      public void testGetActiveCount() throws InterruptedException {
309          final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2);
310 <        final CountDownLatch threadStarted = new CountDownLatch(1);
311 <        final CountDownLatch done = new CountDownLatch(1);
312 <        try {
310 >        try (PoolCleaner cleaner = cleaner(p)) {
311 >            final CountDownLatch threadStarted = new CountDownLatch(1);
312 >            final CountDownLatch done = new CountDownLatch(1);
313              assertEquals(0, p.getActiveCount());
314              p.execute(new CheckedRunnable() {
315                  public void realRun() throws InterruptedException {
# Line 336 | Line 319 | public class ScheduledExecutorTest exten
319                  }});
320              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
321              assertEquals(1, p.getActiveCount());
339        } finally {
322              done.countDown();
341            joinPool(p);
323          }
324      }
325  
# Line 348 | Line 329 | public class ScheduledExecutorTest exten
329       */
330      public void testGetCompletedTaskCount() throws InterruptedException {
331          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2);
332 <        final CountDownLatch threadStarted = new CountDownLatch(1);
333 <        final CountDownLatch threadProceed = new CountDownLatch(1);
334 <        final CountDownLatch threadDone = new CountDownLatch(1);
335 <        try {
332 >        try (PoolCleaner cleaner = cleaner(p)) {
333 >            final CountDownLatch threadStarted = new CountDownLatch(1);
334 >            final CountDownLatch threadProceed = new CountDownLatch(1);
335 >            final CountDownLatch threadDone = new CountDownLatch(1);
336              assertEquals(0, p.getCompletedTaskCount());
337              p.execute(new CheckedRunnable() {
338                  public void realRun() throws InterruptedException {
# Line 370 | Line 351 | public class ScheduledExecutorTest exten
351                      fail("timed out");
352                  Thread.yield();
353              }
373        } finally {
374            joinPool(p);
354          }
355      }
356  
# Line 380 | Line 359 | public class ScheduledExecutorTest exten
359       */
360      public void testGetCorePoolSize() throws InterruptedException {
361          ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
362 <        assertEquals(1, p.getCorePoolSize());
363 <        joinPool(p);
362 >        try (PoolCleaner cleaner = cleaner(p)) {
363 >            assertEquals(1, p.getCorePoolSize());
364 >        }
365      }
366  
367      /**
# Line 393 | Line 373 | public class ScheduledExecutorTest exten
373          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(THREADS);
374          final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
375          final CountDownLatch done = new CountDownLatch(1);
376 <        try {
376 >        try (PoolCleaner cleaner = cleaner(p)) {
377              assertEquals(0, p.getLargestPoolSize());
378              for (int i = 0; i < THREADS; i++)
379                  p.execute(new CheckedRunnable() {
# Line 404 | Line 384 | public class ScheduledExecutorTest exten
384                      }});
385              assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
386              assertEquals(THREADS, p.getLargestPoolSize());
407        } finally {
387              done.countDown();
409            joinPool(p);
410            assertEquals(THREADS, p.getLargestPoolSize());
388          }
389 +        assertEquals(THREADS, p.getLargestPoolSize());
390      }
391  
392      /**
# Line 419 | Line 397 | public class ScheduledExecutorTest exten
397          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
398          final CountDownLatch threadStarted = new CountDownLatch(1);
399          final CountDownLatch done = new CountDownLatch(1);
400 <        try {
400 >        try (PoolCleaner cleaner = cleaner(p)) {
401              assertEquals(0, p.getPoolSize());
402              p.execute(new CheckedRunnable() {
403                  public void realRun() throws InterruptedException {
# Line 429 | Line 407 | public class ScheduledExecutorTest exten
407                  }});
408              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
409              assertEquals(1, p.getPoolSize());
432        } finally {
410              done.countDown();
434            joinPool(p);
411          }
412      }
413  
# Line 441 | Line 417 | public class ScheduledExecutorTest exten
417       */
418      public void testGetTaskCount() throws InterruptedException {
419          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
420 <        final CountDownLatch threadStarted = new CountDownLatch(1);
421 <        final CountDownLatch done = new CountDownLatch(1);
422 <        final int TASKS = 5;
423 <        try {
420 >        try (PoolCleaner cleaner = cleaner(p)) {
421 >            final CountDownLatch threadStarted = new CountDownLatch(1);
422 >            final CountDownLatch done = new CountDownLatch(1);
423 >            final int TASKS = 5;
424              assertEquals(0, p.getTaskCount());
425              for (int i = 0; i < TASKS; i++)
426                  p.execute(new CheckedRunnable() {
# Line 454 | Line 430 | public class ScheduledExecutorTest exten
430                      }});
431              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
432              assertEquals(TASKS, p.getTaskCount());
457        } finally {
433              done.countDown();
459            joinPool(p);
434          }
435      }
436  
# Line 464 | Line 438 | public class ScheduledExecutorTest exten
438       * getThreadFactory returns factory in constructor if not set
439       */
440      public void testGetThreadFactory() throws InterruptedException {
441 <        ThreadFactory tf = new SimpleThreadFactory();
442 <        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf);
443 <        assertSame(tf, p.getThreadFactory());
441 >        ThreadFactory threadFactory = new SimpleThreadFactory();
442 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, threadFactory);
443 >        assertSame(threadFactory, p.getThreadFactory());
444          joinPool(p);
445      }
446  
# Line 474 | Line 448 | public class ScheduledExecutorTest exten
448       * setThreadFactory sets the thread factory returned by getThreadFactory
449       */
450      public void testSetThreadFactory() throws InterruptedException {
451 <        ThreadFactory tf = new SimpleThreadFactory();
451 >        ThreadFactory threadFactory = new SimpleThreadFactory();
452          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
453 <        p.setThreadFactory(tf);
454 <        assertSame(tf, p.getThreadFactory());
455 <        joinPool(p);
453 >        try (PoolCleaner cleaner = cleaner(p)) {
454 >            p.setThreadFactory(threadFactory);
455 >            assertSame(threadFactory, p.getThreadFactory());
456 >        }
457      }
458  
459      /**
# Line 486 | Line 461 | public class ScheduledExecutorTest exten
461       */
462      public void testSetThreadFactoryNull() throws InterruptedException {
463          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
464 <        try {
465 <            p.setThreadFactory(null);
466 <            shouldThrow();
467 <        } catch (NullPointerException success) {
468 <        } finally {
494 <            joinPool(p);
464 >        try (PoolCleaner cleaner = cleaner(p)) {
465 >            try {
466 >                p.setThreadFactory(null);
467 >                shouldThrow();
468 >            } catch (NullPointerException success) {}
469          }
470      }
471  
# Line 515 | Line 489 | public class ScheduledExecutorTest exten
489       */
490      public void testIsTerminated() throws InterruptedException {
491          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
492 <        final CountDownLatch threadStarted = new CountDownLatch(1);
493 <        final CountDownLatch done = new CountDownLatch(1);
494 <        assertFalse(p.isTerminated());
495 <        try {
492 >        try (PoolCleaner cleaner = cleaner(p)) {
493 >            final CountDownLatch threadStarted = new CountDownLatch(1);
494 >            final CountDownLatch done = new CountDownLatch(1);
495 >            assertFalse(p.isTerminated());
496              p.execute(new CheckedRunnable() {
497                  public void realRun() throws InterruptedException {
498                      assertFalse(p.isTerminated());
# Line 528 | Line 502 | public class ScheduledExecutorTest exten
502              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
503              assertFalse(p.isTerminating());
504              done.countDown();
531        } finally {
505              try { p.shutdown(); } catch (SecurityException ok) { return; }
506 +            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
507 +            assertTrue(p.isTerminated());
508          }
534        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
535        assertTrue(p.isTerminated());
509      }
510  
511      /**
# Line 542 | Line 515 | public class ScheduledExecutorTest exten
515          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
516          final CountDownLatch threadStarted = new CountDownLatch(1);
517          final CountDownLatch done = new CountDownLatch(1);
518 <        try {
518 >        try (PoolCleaner cleaner = cleaner(p)) {
519              assertFalse(p.isTerminating());
520              p.execute(new CheckedRunnable() {
521                  public void realRun() throws InterruptedException {
# Line 553 | Line 526 | public class ScheduledExecutorTest exten
526              assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
527              assertFalse(p.isTerminating());
528              done.countDown();
556        } finally {
529              try { p.shutdown(); } catch (SecurityException ok) { return; }
530 +            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
531 +            assertTrue(p.isTerminated());
532 +            assertFalse(p.isTerminating());
533          }
559        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
560        assertTrue(p.isTerminated());
561        assertFalse(p.isTerminating());
534      }
535  
536      /**
# Line 566 | Line 538 | public class ScheduledExecutorTest exten
538       */
539      public void testGetQueue() throws InterruptedException {
540          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
541 <        final CountDownLatch threadStarted = new CountDownLatch(1);
542 <        final CountDownLatch done = new CountDownLatch(1);
543 <        try {
541 >        try (PoolCleaner cleaner = cleaner(p)) {
542 >            final CountDownLatch threadStarted = new CountDownLatch(1);
543 >            final CountDownLatch done = new CountDownLatch(1);
544              ScheduledFuture[] tasks = new ScheduledFuture[5];
545              for (int i = 0; i < tasks.length; i++) {
546                  Runnable r = new CheckedRunnable() {
# Line 582 | Line 554 | public class ScheduledExecutorTest exten
554              BlockingQueue<Runnable> q = p.getQueue();
555              assertTrue(q.contains(tasks[tasks.length - 1]));
556              assertFalse(q.contains(tasks[0]));
585        } finally {
557              done.countDown();
587            joinPool(p);
558          }
559      }
560  
# Line 593 | Line 563 | public class ScheduledExecutorTest exten
563       */
564      public void testRemove() throws InterruptedException {
565          final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
566 <        ScheduledFuture[] tasks = new ScheduledFuture[5];
567 <        final CountDownLatch threadStarted = new CountDownLatch(1);
568 <        final CountDownLatch done = new CountDownLatch(1);
569 <        try {
566 >        try (PoolCleaner cleaner = cleaner(p)) {
567 >            ScheduledFuture[] tasks = new ScheduledFuture[5];
568 >            final CountDownLatch threadStarted = new CountDownLatch(1);
569 >            final CountDownLatch done = new CountDownLatch(1);
570              for (int i = 0; i < tasks.length; i++) {
571                  Runnable r = new CheckedRunnable() {
572                      public void realRun() throws InterruptedException {
# Line 616 | Line 586 | public class ScheduledExecutorTest exten
586              assertTrue(q.contains((Runnable)tasks[3]));
587              assertTrue(p.remove((Runnable)tasks[3]));
588              assertFalse(q.contains((Runnable)tasks[3]));
619        } finally {
589              done.countDown();
621            joinPool(p);
590          }
591      }
592  
# Line 822 | Line 790 | public class ScheduledExecutorTest exten
790       * completed submit of callable returns result
791       */
792      public void testSubmitCallable() throws Exception {
793 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
794 <        try {
793 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
794 >        try (PoolCleaner cleaner = cleaner(e)) {
795              Future<String> future = e.submit(new StringTask());
796              String result = future.get();
797              assertSame(TEST_STRING, result);
830        } finally {
831            joinPool(e);
798          }
799      }
800  
# Line 836 | Line 802 | public class ScheduledExecutorTest exten
802       * completed submit of runnable returns successfully
803       */
804      public void testSubmitRunnable() throws Exception {
805 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
806 <        try {
805 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
806 >        try (PoolCleaner cleaner = cleaner(e)) {
807              Future<?> future = e.submit(new NoOpRunnable());
808              future.get();
809              assertTrue(future.isDone());
844        } finally {
845            joinPool(e);
810          }
811      }
812  
# Line 850 | Line 814 | public class ScheduledExecutorTest exten
814       * completed submit of (runnable, result) returns result
815       */
816      public void testSubmitRunnable2() throws Exception {
817 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
818 <        try {
817 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
818 >        try (PoolCleaner cleaner = cleaner(e)) {
819              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
820              String result = future.get();
821              assertSame(TEST_STRING, result);
858        } finally {
859            joinPool(e);
822          }
823      }
824  
# Line 864 | Line 826 | public class ScheduledExecutorTest exten
826       * invokeAny(null) throws NPE
827       */
828      public void testInvokeAny1() throws Exception {
829 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
830 <        try {
831 <            e.invokeAny(null);
832 <            shouldThrow();
833 <        } catch (NullPointerException success) {
834 <        } finally {
873 <            joinPool(e);
829 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
830 >        try (PoolCleaner cleaner = cleaner(e)) {
831 >            try {
832 >                e.invokeAny(null);
833 >                shouldThrow();
834 >            } catch (NullPointerException success) {}
835          }
836      }
837  
# Line 878 | Line 839 | public class ScheduledExecutorTest exten
839       * invokeAny(empty collection) throws IAE
840       */
841      public void testInvokeAny2() throws Exception {
842 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
843 <        try {
844 <            e.invokeAny(new ArrayList<Callable<String>>());
845 <            shouldThrow();
846 <        } catch (IllegalArgumentException success) {
847 <        } finally {
887 <            joinPool(e);
842 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
843 >        try (PoolCleaner cleaner = cleaner(e)) {
844 >            try {
845 >                e.invokeAny(new ArrayList<Callable<String>>());
846 >                shouldThrow();
847 >            } catch (IllegalArgumentException success) {}
848          }
849      }
850  
# Line 893 | Line 853 | public class ScheduledExecutorTest exten
853       */
854      public void testInvokeAny3() throws Exception {
855          CountDownLatch latch = new CountDownLatch(1);
856 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
857 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
858 <        l.add(latchAwaitingStringTask(latch));
859 <        l.add(null);
860 <        try {
861 <            e.invokeAny(l);
862 <            shouldThrow();
863 <        } catch (NullPointerException success) {
864 <        } finally {
856 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
857 >        try (PoolCleaner cleaner = cleaner(e)) {
858 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
859 >            l.add(latchAwaitingStringTask(latch));
860 >            l.add(null);
861 >            try {
862 >                e.invokeAny(l);
863 >                shouldThrow();
864 >            } catch (NullPointerException success) {}
865              latch.countDown();
906            joinPool(e);
866          }
867      }
868  
# Line 911 | Line 870 | public class ScheduledExecutorTest exten
870       * invokeAny(c) throws ExecutionException if no task completes
871       */
872      public void testInvokeAny4() throws Exception {
873 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
874 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
875 <        l.add(new NPETask());
876 <        try {
877 <            e.invokeAny(l);
878 <            shouldThrow();
879 <        } catch (ExecutionException success) {
880 <            assertTrue(success.getCause() instanceof NullPointerException);
881 <        } finally {
882 <            joinPool(e);
873 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
874 >        try (PoolCleaner cleaner = cleaner(e)) {
875 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
876 >            l.add(new NPETask());
877 >            try {
878 >                e.invokeAny(l);
879 >                shouldThrow();
880 >            } catch (ExecutionException success) {
881 >                assertTrue(success.getCause() instanceof NullPointerException);
882 >            }
883          }
884      }
885  
# Line 928 | Line 887 | public class ScheduledExecutorTest exten
887       * invokeAny(c) returns result of some task
888       */
889      public void testInvokeAny5() throws Exception {
890 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
891 <        try {
890 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
891 >        try (PoolCleaner cleaner = cleaner(e)) {
892              List<Callable<String>> l = new ArrayList<Callable<String>>();
893              l.add(new StringTask());
894              l.add(new StringTask());
895              String result = e.invokeAny(l);
896              assertSame(TEST_STRING, result);
938        } finally {
939            joinPool(e);
897          }
898      }
899  
# Line 944 | Line 901 | public class ScheduledExecutorTest exten
901       * invokeAll(null) throws NPE
902       */
903      public void testInvokeAll1() throws Exception {
904 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
905 <        try {
906 <            e.invokeAll(null);
907 <            shouldThrow();
908 <        } catch (NullPointerException success) {
909 <        } finally {
953 <            joinPool(e);
904 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
905 >        try (PoolCleaner cleaner = cleaner(e)) {
906 >            try {
907 >                e.invokeAll(null);
908 >                shouldThrow();
909 >            } catch (NullPointerException success) {}
910          }
911      }
912  
# Line 958 | Line 914 | public class ScheduledExecutorTest exten
914       * invokeAll(empty collection) returns empty collection
915       */
916      public void testInvokeAll2() throws Exception {
917 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
918 <        try {
917 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
918 >        try (PoolCleaner cleaner = cleaner(e)) {
919              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
920              assertTrue(r.isEmpty());
965        } finally {
966            joinPool(e);
921          }
922      }
923  
# Line 971 | Line 925 | public class ScheduledExecutorTest exten
925       * invokeAll(c) throws NPE if c has null elements
926       */
927      public void testInvokeAll3() throws Exception {
928 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
929 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
930 <        l.add(new StringTask());
931 <        l.add(null);
932 <        try {
933 <            e.invokeAll(l);
934 <            shouldThrow();
935 <        } catch (NullPointerException success) {
936 <        } finally {
983 <            joinPool(e);
928 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
929 >        try (PoolCleaner cleaner = cleaner(e)) {
930 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
931 >            l.add(new StringTask());
932 >            l.add(null);
933 >            try {
934 >                e.invokeAll(l);
935 >                shouldThrow();
936 >            } catch (NullPointerException success) {}
937          }
938      }
939  
# Line 988 | Line 941 | public class ScheduledExecutorTest exten
941       * get of invokeAll(c) throws exception on failed task
942       */
943      public void testInvokeAll4() throws Exception {
944 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
945 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
946 <        l.add(new NPETask());
947 <        List<Future<String>> futures = e.invokeAll(l);
948 <        assertEquals(1, futures.size());
949 <        try {
950 <            futures.get(0).get();
951 <            shouldThrow();
952 <        } catch (ExecutionException success) {
953 <            assertTrue(success.getCause() instanceof NullPointerException);
954 <        } finally {
955 <            joinPool(e);
944 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
945 >        try (PoolCleaner cleaner = cleaner(e)) {
946 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
947 >            l.add(new NPETask());
948 >            List<Future<String>> futures = e.invokeAll(l);
949 >            assertEquals(1, futures.size());
950 >            try {
951 >                futures.get(0).get();
952 >                shouldThrow();
953 >            } catch (ExecutionException success) {
954 >                assertTrue(success.getCause() instanceof NullPointerException);
955 >            }
956          }
957      }
958  
# Line 1007 | Line 960 | public class ScheduledExecutorTest exten
960       * invokeAll(c) returns results of all completed tasks
961       */
962      public void testInvokeAll5() throws Exception {
963 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
964 <        try {
963 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
964 >        try (PoolCleaner cleaner = cleaner(e)) {
965              List<Callable<String>> l = new ArrayList<Callable<String>>();
966              l.add(new StringTask());
967              l.add(new StringTask());
# Line 1016 | Line 969 | public class ScheduledExecutorTest exten
969              assertEquals(2, futures.size());
970              for (Future<String> future : futures)
971                  assertSame(TEST_STRING, future.get());
1019        } finally {
1020            joinPool(e);
972          }
973      }
974  
# Line 1025 | Line 976 | public class ScheduledExecutorTest exten
976       * timed invokeAny(null) throws NPE
977       */
978      public void testTimedInvokeAny1() throws Exception {
979 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
980 <        try {
981 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
982 <            shouldThrow();
983 <        } catch (NullPointerException success) {
984 <        } finally {
1034 <            joinPool(e);
979 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
980 >        try (PoolCleaner cleaner = cleaner(e)) {
981 >            try {
982 >                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
983 >                shouldThrow();
984 >            } catch (NullPointerException success) {}
985          }
986      }
987  
# Line 1039 | Line 989 | public class ScheduledExecutorTest exten
989       * timed invokeAny(,,null) throws NPE
990       */
991      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
992 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
993 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
994 <        l.add(new StringTask());
995 <        try {
996 <            e.invokeAny(l, MEDIUM_DELAY_MS, null);
997 <            shouldThrow();
998 <        } catch (NullPointerException success) {
999 <        } finally {
1050 <            joinPool(e);
992 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
993 >        try (PoolCleaner cleaner = cleaner(e)) {
994 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
995 >            l.add(new StringTask());
996 >            try {
997 >                e.invokeAny(l, MEDIUM_DELAY_MS, null);
998 >                shouldThrow();
999 >            } catch (NullPointerException success) {}
1000          }
1001      }
1002  
# Line 1055 | Line 1004 | public class ScheduledExecutorTest exten
1004       * timed invokeAny(empty collection) throws IAE
1005       */
1006      public void testTimedInvokeAny2() throws Exception {
1007 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1008 <        try {
1009 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1010 <            shouldThrow();
1011 <        } catch (IllegalArgumentException success) {
1012 <        } finally {
1064 <            joinPool(e);
1007 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1008 >        try (PoolCleaner cleaner = cleaner(e)) {
1009 >            try {
1010 >                e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1011 >                shouldThrow();
1012 >            } catch (IllegalArgumentException success) {}
1013          }
1014      }
1015  
# Line 1070 | Line 1018 | public class ScheduledExecutorTest exten
1018       */
1019      public void testTimedInvokeAny3() throws Exception {
1020          CountDownLatch latch = new CountDownLatch(1);
1021 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1022 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1023 <        l.add(latchAwaitingStringTask(latch));
1024 <        l.add(null);
1025 <        try {
1026 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1027 <            shouldThrow();
1028 <        } catch (NullPointerException success) {
1029 <        } finally {
1021 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1022 >        try (PoolCleaner cleaner = cleaner(e)) {
1023 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1024 >            l.add(latchAwaitingStringTask(latch));
1025 >            l.add(null);
1026 >            try {
1027 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1028 >                shouldThrow();
1029 >            } catch (NullPointerException success) {}
1030              latch.countDown();
1083            joinPool(e);
1031          }
1032      }
1033  
# Line 1088 | Line 1035 | public class ScheduledExecutorTest exten
1035       * timed invokeAny(c) throws ExecutionException if no task completes
1036       */
1037      public void testTimedInvokeAny4() throws Exception {
1038 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1039 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1040 <        l.add(new NPETask());
1041 <        try {
1042 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1043 <            shouldThrow();
1044 <        } catch (ExecutionException success) {
1045 <            assertTrue(success.getCause() instanceof NullPointerException);
1046 <        } finally {
1047 <            joinPool(e);
1038 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1039 >        try (PoolCleaner cleaner = cleaner(e)) {
1040 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1041 >            l.add(new NPETask());
1042 >            try {
1043 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1044 >                shouldThrow();
1045 >            } catch (ExecutionException success) {
1046 >                assertTrue(success.getCause() instanceof NullPointerException);
1047 >            }
1048          }
1049      }
1050  
# Line 1105 | Line 1052 | public class ScheduledExecutorTest exten
1052       * timed invokeAny(c) returns result of some task
1053       */
1054      public void testTimedInvokeAny5() throws Exception {
1055 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1056 <        try {
1055 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1056 >        try (PoolCleaner cleaner = cleaner(e)) {
1057              List<Callable<String>> l = new ArrayList<Callable<String>>();
1058              l.add(new StringTask());
1059              l.add(new StringTask());
1060              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1061              assertSame(TEST_STRING, result);
1115        } finally {
1116            joinPool(e);
1062          }
1063      }
1064  
# Line 1121 | Line 1066 | public class ScheduledExecutorTest exten
1066       * timed invokeAll(null) throws NPE
1067       */
1068      public void testTimedInvokeAll1() throws Exception {
1069 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1070 <        try {
1071 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1072 <            shouldThrow();
1073 <        } catch (NullPointerException success) {
1074 <        } finally {
1130 <            joinPool(e);
1069 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1070 >        try (PoolCleaner cleaner = cleaner(e)) {
1071 >            try {
1072 >                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1073 >                shouldThrow();
1074 >            } catch (NullPointerException success) {}
1075          }
1076      }
1077  
# Line 1135 | Line 1079 | public class ScheduledExecutorTest exten
1079       * timed invokeAll(,,null) throws NPE
1080       */
1081      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1082 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1083 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1084 <        l.add(new StringTask());
1085 <        try {
1086 <            e.invokeAll(l, MEDIUM_DELAY_MS, null);
1087 <            shouldThrow();
1088 <        } catch (NullPointerException success) {
1089 <        } finally {
1146 <            joinPool(e);
1082 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1083 >        try (PoolCleaner cleaner = cleaner(e)) {
1084 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1085 >            l.add(new StringTask());
1086 >            try {
1087 >                e.invokeAll(l, MEDIUM_DELAY_MS, null);
1088 >                shouldThrow();
1089 >            } catch (NullPointerException success) {}
1090          }
1091      }
1092  
# Line 1151 | Line 1094 | public class ScheduledExecutorTest exten
1094       * timed invokeAll(empty collection) returns empty collection
1095       */
1096      public void testTimedInvokeAll2() throws Exception {
1097 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1098 <        try {
1099 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1097 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1098 >        try (PoolCleaner cleaner = cleaner(e)) {
1099 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(),
1100 >                                                 MEDIUM_DELAY_MS, MILLISECONDS);
1101              assertTrue(r.isEmpty());
1158        } finally {
1159            joinPool(e);
1102          }
1103      }
1104  
# Line 1164 | Line 1106 | public class ScheduledExecutorTest exten
1106       * timed invokeAll(c) throws NPE if c has null elements
1107       */
1108      public void testTimedInvokeAll3() throws Exception {
1109 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1110 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1111 <        l.add(new StringTask());
1112 <        l.add(null);
1113 <        try {
1114 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1115 <            shouldThrow();
1116 <        } catch (NullPointerException success) {
1117 <        } finally {
1176 <            joinPool(e);
1109 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1110 >        try (PoolCleaner cleaner = cleaner(e)) {
1111 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1112 >            l.add(new StringTask());
1113 >            l.add(null);
1114 >            try {
1115 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1116 >                shouldThrow();
1117 >            } catch (NullPointerException success) {}
1118          }
1119      }
1120  
# Line 1181 | Line 1122 | public class ScheduledExecutorTest exten
1122       * get of element of invokeAll(c) throws exception on failed task
1123       */
1124      public void testTimedInvokeAll4() throws Exception {
1125 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1126 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1127 <        l.add(new NPETask());
1128 <        List<Future<String>> futures =
1129 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1130 <        assertEquals(1, futures.size());
1131 <        try {
1132 <            futures.get(0).get();
1133 <            shouldThrow();
1134 <        } catch (ExecutionException success) {
1135 <            assertTrue(success.getCause() instanceof NullPointerException);
1136 <        } finally {
1137 <            joinPool(e);
1125 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1126 >        try (PoolCleaner cleaner = cleaner(e)) {
1127 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1128 >            l.add(new NPETask());
1129 >            List<Future<String>> futures =
1130 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1131 >            assertEquals(1, futures.size());
1132 >            try {
1133 >                futures.get(0).get();
1134 >                shouldThrow();
1135 >            } catch (ExecutionException success) {
1136 >                assertTrue(success.getCause() instanceof NullPointerException);
1137 >            }
1138          }
1139      }
1140  
# Line 1201 | Line 1142 | public class ScheduledExecutorTest exten
1142       * timed invokeAll(c) returns results of all completed tasks
1143       */
1144      public void testTimedInvokeAll5() throws Exception {
1145 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1146 <        try {
1145 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1146 >        try (PoolCleaner cleaner = cleaner(e)) {
1147              List<Callable<String>> l = new ArrayList<Callable<String>>();
1148              l.add(new StringTask());
1149              l.add(new StringTask());
# Line 1211 | Line 1152 | public class ScheduledExecutorTest exten
1152              assertEquals(2, futures.size());
1153              for (Future<String> future : futures)
1154                  assertSame(TEST_STRING, future.get());
1214        } finally {
1215            joinPool(e);
1155          }
1156      }
1157  
# Line 1220 | Line 1159 | public class ScheduledExecutorTest exten
1159       * timed invokeAll(c) cancels tasks not completed by timeout
1160       */
1161      public void testTimedInvokeAll6() throws Exception {
1162 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1163 <        try {
1162 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1163 >        try (PoolCleaner cleaner = cleaner(e)) {
1164              for (long timeout = timeoutMillis();;) {
1165                  List<Callable<String>> tasks = new ArrayList<>();
1166                  tasks.add(new StringTask("0"));
# Line 1245 | Line 1184 | public class ScheduledExecutorTest exten
1184                          fail("expected exactly one task to be cancelled");
1185                  }
1186              }
1248        } finally {
1249            joinPool(e);
1187          }
1188      }
1189  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines