class CallableTask implements Callable<Boolean>{ public Boolean call() throws Exception { // InputStream in = new FileInputStream(new File("xx.pdf")); int num = 3/0; return false; }
}
结果为:
1 2 3 4 5 6 7 8 9 10 11 12
java.util.concurrent.ExecutionException: java.lang.ArithmeticException: / by zero at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222) at java.util.concurrent.FutureTask.get(FutureTask.java:83) at my.ThreadExceptionTest.main(ThreadExceptionTest.java:21) Caused by: java.lang.ArithmeticException: / by zero at my.CallableTask.call(ThreadExceptionTest.java:57) at my.CallableTask.call(ThreadExceptionTest.java:1) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)