线程池ExecutorService不执行shutdown()方法,程序一直处在运行状态。

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

猜你喜欢

转载自blog.csdn.net/qq_41782949/article/details/90711872