|
3 | 3 | // We make no guarantees that this code is fit for any purpose. |
4 | 4 | // Visit http://OnJava8.com for more book information. |
5 | 5 | import java.util.concurrent.*; |
6 | | -import onjava.TimedAbort; |
7 | 6 |
|
8 | 7 | class ExceptionThread2 implements Runnable { |
9 | 8 | @Override |
@@ -40,21 +39,17 @@ public Thread newThread(Runnable r) { |
40 | 39 |
|
41 | 40 | public class CaptureUncaughtException { |
42 | 41 | public static void main(String[] args) { |
43 | | - new TimedAbort(4); |
44 | 42 | ExecutorService exec = Executors.newCachedThreadPool( |
45 | 43 | new HandlerThreadFactory()); |
46 | 44 | exec.execute(new ExceptionThread2()); |
| 45 | + exec.shutdown(); |
47 | 46 | } |
48 | 47 | } |
49 | 48 | /* Output: |
50 | | -HandlerThreadFactory@14991ad creating new Thread |
51 | | -created Thread[Thread-1,5,main] |
52 | | -eh = MyUncaughtExceptionHandler@d93b30 |
53 | | -run() by Thread-1 |
54 | | -eh = MyUncaughtExceptionHandler@d93b30 |
55 | | -HandlerThreadFactory@14991ad creating new Thread |
56 | | -created Thread[Thread-2,5,main] |
57 | | -eh = MyUncaughtExceptionHandler@1351c58 |
| 49 | +HandlerThreadFactory@4e25154f creating new Thread |
| 50 | +created Thread[Thread-0,5,main] |
| 51 | +eh = MyUncaughtExceptionHandler@70dea4e |
| 52 | +run() by Thread-0 |
| 53 | +eh = MyUncaughtExceptionHandler@70dea4e |
58 | 54 | caught java.lang.RuntimeException |
59 | | -TimedAbort 4 |
60 | 55 | */ |
0 commit comments