执行完shutdown()方法后,即关闭线程池,已经创建的线程会继续执行,不能再创建新线程,要想终止正在执行 的任务,调用shutdowNow()方法。
public static void testHelloworld() throws Exception {
ExecutorService threadPool= Executors.newFixedThreadPool(2);
Future future=threadPool.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
return 11;
}
});
//threadPool.shutdown();这里注释掉
System.out.println("++"+future.get());
System.out.println("--"+future.isCancelled());
System.out.println("==="+future.isDone());
}
public static void main(String[] args) throws Exception{
testHelloworld();
}
执行threadPool.shutdown()后。
如果注释掉System.out.println("++"+future.get()),System.out.println("==="+future.isDone());输出为false