
关于线程池关闭后对于一个已经关闭的线程池调用 execute 方法会直接抛出 RejectedExecutionException 异常ExecutorServicepoolExecutors.newSingleThreadExecutor();pool.shutdown();System.out.println(线程池关闭了);try{Thread.sleep(5*1000);}catch(InterruptedExceptione){e.printStackTrace();}System.out.println(尝试再提交任务);pool.execute(()-System.out.println(执行任务));# 输出结果 线程池关闭了 尝试再提交任务 Exception in thread main java.util.concurrent.RejectedExecutionException对于一个已经关闭的线程池调用 shutdown 或 shutdownNow 方法不会抛出异常也不会产生任何副作用这些方法被设计为幂等的ExecutorServicepoolExecutors.newSingleThreadExecutor();pool.shutdown();System.out.println(线程池关闭了);try{Thread.sleep(5*1000);}catch(InterruptedExceptione){e.printStackTrace();}System.out.println(尝试再关闭线程池);pool.shutdown();# 输出结果 线程池关闭了 尝试再关闭线程池