67,513
社区成员
发帖
与我相关
我的任务
分享
public void execute(JobExecutionContext arg0) throws JobExecutionException {
ExecutorService pool = Executors.newCachedThreadPool(); //1
// ExecutorService pool = Executors.newFixedThreadPool(2); //2
for(int i=0 ; i<2 ;i++){
pool.execute(new ThreadListener());
}
System.out.println(pool.shutdownNow().size());
}
public class ThreadListener implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(new Date()+" "+Thread.currentThread().getName()+" 正在运行");
int i = 10/0;
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Exception in thread "pool-8-thread-2" at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
Thu Oct 29 08:18:04 CST 2015 pool-8-thread-2 正在运行
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
java.lang.ArithmeticException: / by zero
at com.yongan.quartz.ThreadListener.run(ThreadListener.java:17)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Thu Oct 29 08:18:06 CST 2015 pool-9-thread-1 正在运行
Thu Oct 29 08:18:06 CST 2015 pool-9-thread-2 正在运行
Exception in thread "pool-9-thread-1" java.lang.ArithmeticException: / by zero
Exception in thread "pool-9-thread-2" at com.yongan.quartz.ThreadListener.run(ThreadListener.java:17)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
0
java.lang.ArithmeticException: / by zero
at com.yongan.quartz.ThreadListener.run(ThreadListener.java:17)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Thu Oct 29 08:18:08 CST 2015 pool-10-thread-1 正在运行
Exception in thread "pool-10-thread-1" java.lang.ArithmeticException: / by zero
at com.yongan.quartz.ThreadListener.run(ThreadListener.java:17)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Thu Oct 29 08:18:08 CST 2015 pool-10-thread-2 正在运行
我打印出来的线程池名,都是在增加。我担心原来的没退出,还在线程池中?