ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadPoolExecutorTest.java
Revision: 1.7
Committed: Fri Sep 26 15:33:14 2003 UTC (20 years, 7 months ago) by dl
Branch: MAIN
Changes since 1.6: +20 -35 lines
Log Message:
Javadoc fixes

File Contents

# Content
1 /*
2 * Written by members of JCP JSR-166 Expert Group and released to the
3 * public domain. Use, modify, and redistribute this code in any way
4 * without acknowledgement. Other contributors include Andrew Wright,
5 * Jeffrey Hayes, Pat Fischer, Mike Judd.
6 */
7
8 import java.util.concurrent.*;
9 import junit.framework.*;
10 import java.util.List;
11
12 public class ThreadPoolExecutorTest extends JSR166TestCase {
13 public static void main(String[] args) {
14 junit.textui.TestRunner.run (suite());
15 }
16 public static Test suite() {
17 return new TestSuite(ThreadPoolExecutorTest.class);
18 }
19
20
21 /**
22 * execute successfully executes a runnable
23 */
24 public void testExecute() {
25 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
26 try {
27 p1.execute(new Runnable() {
28 public void run() {
29 try {
30 Thread.sleep(SHORT_DELAY_MS);
31 } catch(InterruptedException e){
32 threadUnexpectedException();
33 }
34 }
35 });
36 Thread.sleep(SMALL_DELAY_MS);
37 } catch(InterruptedException e){
38 unexpectedException();
39 }
40 joinPool(p1);
41 }
42
43 /**
44 * getActiveCount increases but doesn't overestimate, when a
45 * thread becomes active
46 */
47 public void testGetActiveCount() {
48 ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
49 assertEquals(0, p2.getActiveCount());
50 p2.execute(new MediumRunnable());
51 try {
52 Thread.sleep(SHORT_DELAY_MS);
53 } catch(Exception e){
54 unexpectedException();
55 }
56 assertEquals(1, p2.getActiveCount());
57 joinPool(p2);
58 }
59
60 /**
61 * getCompletedTaskCount increases, but doesn't overestimate,
62 * when tasks complete
63 */
64 public void testGetCompletedTaskCount() {
65 ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
66 assertEquals(0, p2.getCompletedTaskCount());
67 p2.execute(new ShortRunnable());
68 try {
69 Thread.sleep(MEDIUM_DELAY_MS);
70 } catch(Exception e){
71 unexpectedException();
72 }
73 assertEquals(1, p2.getCompletedTaskCount());
74 p2.shutdown();
75 joinPool(p2);
76 }
77
78 /**
79 * getCorePoolSize returns size given in constructor if not otherwise set
80 */
81 public void testGetCorePoolSize() {
82 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
83 assertEquals(1, p1.getCorePoolSize());
84 joinPool(p1);
85 }
86
87 /**
88 * getKeepAliveTime returns value given in constructor if not otherwise set
89 */
90 public void testGetKeepAliveTime() {
91 ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
92 assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS));
93 joinPool(p2);
94 }
95
96 /**
97 * getLargestPoolSize increases, but doesn't overestimate, when
98 * multiple threads active
99 */
100 public void testGetLargestPoolSize() {
101 ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
102 try {
103 assertEquals(0, p2.getLargestPoolSize());
104 p2.execute(new MediumRunnable());
105 p2.execute(new MediumRunnable());
106 Thread.sleep(SHORT_DELAY_MS);
107 assertEquals(2, p2.getLargestPoolSize());
108 } catch(Exception e){
109 unexpectedException();
110 }
111 joinPool(p2);
112 }
113
114 /**
115 * getMaximumPoolSize returns value given in constructor if not
116 * otherwise set
117 */
118 public void testGetMaximumPoolSize() {
119 ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
120 assertEquals(2, p2.getMaximumPoolSize());
121 joinPool(p2);
122 }
123
124 /**
125 * getPoolSize increases, but doesn't overestimate, when threads
126 * become active
127 */
128 public void testGetPoolSize() {
129 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
130 assertEquals(0, p1.getPoolSize());
131 p1.execute(new MediumRunnable());
132 assertEquals(1, p1.getPoolSize());
133 joinPool(p1);
134 }
135
136 /**
137 * getTaskCount increases, but doesn't overestimate, when tasks submitted
138 */
139 public void testGetTaskCount() {
140 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
141 try {
142 assertEquals(0, p1.getTaskCount());
143 p1.execute(new MediumRunnable());
144 Thread.sleep(SHORT_DELAY_MS);
145 assertEquals(1, p1.getTaskCount());
146 } catch(Exception e){
147 unexpectedException();
148 }
149 joinPool(p1);
150 }
151
152 /**
153 * isShutDown is false before shutdown, true after
154 */
155 public void testIsShutdown() {
156
157 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
158 assertFalse(p1.isShutdown());
159 p1.shutdown();
160 assertTrue(p1.isShutdown());
161 joinPool(p1);
162 }
163
164
165 /**
166 * isTerminated is false before termination, true after
167 */
168 public void testIsTerminated() {
169 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
170 assertFalse(p1.isTerminated());
171 try {
172 p1.execute(new MediumRunnable());
173 } finally {
174 p1.shutdown();
175 }
176 try {
177 assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
178 assertTrue(p1.isTerminated());
179 } catch(Exception e){
180 unexpectedException();
181 }
182 }
183
184 /**
185 * isTerminating is not true when running or when terminated
186 */
187 public void testIsTerminating() {
188 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
189 assertFalse(p1.isTerminating());
190 try {
191 p1.execute(new SmallRunnable());
192 assertFalse(p1.isTerminating());
193 } finally {
194 p1.shutdown();
195 }
196 try {
197 assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
198 assertTrue(p1.isTerminated());
199 assertFalse(p1.isTerminating());
200 } catch(Exception e){
201 unexpectedException();
202 }
203 }
204
205 /**
206 * purge removes cancelled tasks from the queue
207 */
208 public void testPurge() {
209 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
210 CancellableTask[] tasks = new CancellableTask[5];
211 for(int i = 0; i < 5; i++){
212 tasks[i] = new CancellableTask(new MediumPossiblyInterruptedRunnable());
213 p1.execute(tasks[i]);
214 }
215 tasks[4].cancel(true);
216 tasks[3].cancel(true);
217 p1.purge();
218 long count = p1.getTaskCount();
219 assertTrue(count >= 2 && count < 5);
220 joinPool(p1);
221 }
222
223 /**
224 * shutDownNow returns a list containing tasks that were not run
225 */
226 public void testShutDownNow() {
227 ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
228 List l;
229 try {
230 for(int i = 0; i < 5; i++)
231 p1.execute(new MediumPossiblyInterruptedRunnable());
232 }
233 finally {
234 l = p1.shutdownNow();
235 }
236 assertTrue(p1.isShutdown());
237 assertTrue(l.size() <= 4);
238 }
239
240 // Exception Tests
241
242
243 /**
244 * Constructor throws if corePoolSize argument is less than zero
245 */
246 public void testConstructor1() {
247 try {
248 new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
249 shouldThrow();
250 }
251 catch (IllegalArgumentException success){}
252 }
253
254 /**
255 * Constructor throws if maximumPoolSize is less than zero
256 */
257 public void testConstructor2() {
258 try {
259 new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
260 shouldThrow();
261 }
262 catch (IllegalArgumentException success){}
263 }
264
265 /**
266 * Constructor throws if maximumPoolSize is equal to zero
267 */
268 public void testConstructor3() {
269 try {
270 new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
271 shouldThrow();
272 }
273 catch (IllegalArgumentException success){}
274 }
275
276 /**
277 * Constructor throws if keepAliveTime is less than zero
278 */
279 public void testConstructor4() {
280 try {
281 new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
282 shouldThrow();
283 }
284 catch (IllegalArgumentException success){}
285 }
286
287 /**
288 * Constructor throws if corePoolSize is greater than the maximumPoolSize
289 */
290 public void testConstructor5() {
291 try {
292 new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
293 shouldThrow();
294 }
295 catch (IllegalArgumentException success){}
296 }
297
298 /**
299 * Constructor throws if workQueue is set to null
300 */
301 public void testNullPointerException() {
302 try {
303 new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null);
304 shouldThrow();
305 }
306 catch (NullPointerException success){}
307 }
308
309
310
311 /**
312 * Constructor throws if corePoolSize argument is less than zero
313 */
314 public void testConstructor6() {
315 try {
316 new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
317 shouldThrow();
318 } catch (IllegalArgumentException success){}
319 }
320
321 /**
322 * Constructor throws if maximumPoolSize is less than zero
323 */
324 public void testConstructor7() {
325 try {
326 new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
327 shouldThrow();
328 }
329 catch (IllegalArgumentException success){}
330 }
331
332 /**
333 * Constructor throws if maximumPoolSize is equal to zero
334 */
335 public void testConstructor8() {
336 try {
337 new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
338 shouldThrow();
339 }
340 catch (IllegalArgumentException success){}
341 }
342
343 /**
344 * Constructor throws if keepAliveTime is less than zero
345 */
346 public void testConstructor9() {
347 try {
348 new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
349 shouldThrow();
350 }
351 catch (IllegalArgumentException success){}
352 }
353
354 /**
355 * Constructor throws if corePoolSize is greater than the maximumPoolSize
356 */
357 public void testConstructor10() {
358 try {
359 new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
360 shouldThrow();
361 }
362 catch (IllegalArgumentException success){}
363 }
364
365 /**
366 * Constructor throws if workQueue is set to null
367 */
368 public void testNullPointerException2() {
369 try {
370 new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
371 shouldThrow();
372 }
373 catch (NullPointerException success){}
374 }
375
376 /**
377 * Constructor throws if threadFactory is set to null
378 */
379 public void testNullPointerException3() {
380 try {
381 ThreadFactory f = null;
382 new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
383 shouldThrow();
384 }
385 catch (NullPointerException success){}
386 }
387
388
389 /**
390 * Constructor throws if corePoolSize argument is less than zero
391 */
392 public void testConstructor11() {
393 try {
394 new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
395 shouldThrow();
396 }
397 catch (IllegalArgumentException success){}
398 }
399
400 /**
401 * Constructor throws if maximumPoolSize is less than zero
402 */
403 public void testConstructor12() {
404 try {
405 new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
406 shouldThrow();
407 }
408 catch (IllegalArgumentException success){}
409 }
410
411 /**
412 * Constructor throws if maximumPoolSize is equal to zero
413 */
414 public void testConstructor13() {
415 try {
416 new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
417 shouldThrow();
418 }
419 catch (IllegalArgumentException success){}
420 }
421
422 /**
423 * Constructor throws if keepAliveTime is less than zero
424 */
425 public void testConstructor14() {
426 try {
427 new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
428 shouldThrow();
429 }
430 catch (IllegalArgumentException success){}
431 }
432
433 /**
434 * Constructor throws if corePoolSize is greater than the maximumPoolSize
435 */
436 public void testConstructor15() {
437 try {
438 new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
439 shouldThrow();
440 }
441 catch (IllegalArgumentException success){}
442 }
443
444 /**
445 * Constructor throws if workQueue is set to null
446 */
447 public void testNullPointerException4() {
448 try {
449 new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
450 shouldThrow();
451 }
452 catch (NullPointerException success){}
453 }
454
455 /**
456 * Constructor throws if handler is set to null
457 */
458 public void testNullPointerException5() {
459 try {
460 RejectedExecutionHandler r = null;
461 new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
462 shouldThrow();
463 }
464 catch (NullPointerException success){}
465 }
466
467
468 /**
469 * Constructor throws if corePoolSize argument is less than zero
470 */
471 public void testConstructor16() {
472 try {
473 new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
474 shouldThrow();
475 }
476 catch (IllegalArgumentException success){}
477 }
478
479 /**
480 * Constructor throws if maximumPoolSize is less than zero
481 */
482 public void testConstructor17() {
483 try {
484 new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
485 shouldThrow();
486 }
487 catch (IllegalArgumentException success){}
488 }
489
490 /**
491 * Constructor throws if maximumPoolSize is equal to zero
492 */
493 public void testConstructor18() {
494 try {
495 new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
496 shouldThrow();
497 }
498 catch (IllegalArgumentException success){}
499 }
500
501 /**
502 * Constructor throws if keepAliveTime is less than zero
503 */
504 public void testConstructor19() {
505 try {
506 new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
507 shouldThrow();
508 }
509 catch (IllegalArgumentException success){}
510 }
511
512 /**
513 * Constructor throws if corePoolSize is greater than the maximumPoolSize
514 */
515 public void testConstructor20() {
516 try {
517 new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
518 shouldThrow();
519 }
520 catch (IllegalArgumentException success){}
521 }
522
523 /**
524 * Constructor throws if workQueue is set to null
525 */
526 public void testNullPointerException6() {
527 try {
528 new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
529 shouldThrow();
530 }
531 catch (NullPointerException success){}
532 }
533
534 /**
535 * Constructor throws if handler is set to null
536 */
537 public void testNullPointerException7() {
538 try {
539 RejectedExecutionHandler r = null;
540 new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
541 shouldThrow();
542 }
543 catch (NullPointerException success){}
544 }
545
546 /**
547 * Constructor throws if ThreadFactory is set top null
548 */
549 public void testNullPointerException8() {
550 try {
551 ThreadFactory f = null;
552 new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
553 shouldThrow();
554 }
555 catch (NullPointerException successdn8){}
556 }
557
558
559 /**
560 * execute throws RejectedExecutionException if shutdown
561 */
562 public void testRejectedExecutionException() {
563 ThreadPoolExecutor tpe = null;
564 try {
565 tpe = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1));
566 } catch(Exception e){}
567 tpe.shutdown();
568 try {
569 tpe.execute(new NoOpRunnable());
570 shouldThrow();
571 } catch(RejectedExecutionException success){}
572
573 joinPool(tpe);
574 }
575
576 /**
577 * execute throws RejectedExecutionException
578 * if saturated.
579 */
580 public void testSaturatedExecute() {
581 ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
582 try {
583
584 for(int i = 0; i < 5; ++i){
585 p.execute(new MediumRunnable());
586 }
587 shouldThrow();
588 } catch(RejectedExecutionException success){}
589 joinPool(p);
590 }
591
592 /**
593 * execute (null) throws NPE
594 */
595 public void testExecuteNull() {
596 ThreadPoolExecutor tpe = null;
597 try {
598 tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
599 tpe.execute(null);
600 shouldThrow();
601 } catch(NullPointerException success){}
602
603 joinPool(tpe);
604 }
605
606 /**
607 * setCorePoolSize of netaitev value throws IllegalArgumentException
608 */
609 public void testCorePoolSizeIllegalArgumentException() {
610 ThreadPoolExecutor tpe = null;
611 try {
612 tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
613 } catch(Exception e){}
614 try {
615 tpe.setCorePoolSize(-1);
616 shouldThrow();
617 } catch(IllegalArgumentException success){
618 } finally {
619 tpe.shutdown();
620 }
621 joinPool(tpe);
622 }
623
624 /**
625 * setMaximumPoolSize(int) throws IllegalArgumentException if
626 * given a value less the core pool size
627 */
628 public void testMaximumPoolSizeIllegalArgumentException() {
629 ThreadPoolExecutor tpe = null;
630 try {
631 tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
632 } catch(Exception e){}
633 try {
634 tpe.setMaximumPoolSize(1);
635 shouldThrow();
636 } catch(IllegalArgumentException success){
637 } finally {
638 tpe.shutdown();
639 }
640 joinPool(tpe);
641 }
642
643 /**
644 * setMaximumPoolSize throws IllegalArgumentException
645 * if given a negative value
646 */
647 public void testMaximumPoolSizeIllegalArgumentException2() {
648 ThreadPoolExecutor tpe = null;
649 try {
650 tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
651 } catch(Exception e){}
652 try {
653 tpe.setMaximumPoolSize(-1);
654 shouldThrow();
655 } catch(IllegalArgumentException success){
656 } finally {
657 tpe.shutdown();
658 }
659 joinPool(tpe);
660 }
661
662
663 /**
664 * setKeepAliveTime throws IllegalArgumentException
665 * when given a negative value
666 */
667 public void testKeepAliveTimeIllegalArgumentException() {
668 ThreadPoolExecutor tpe = null;
669 try {
670 tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
671 } catch(Exception e){}
672
673 try {
674 tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS);
675 shouldThrow();
676 } catch(IllegalArgumentException success){
677 } finally {
678 tpe.shutdown();
679 }
680 joinPool(tpe);
681 }
682
683 }