shutdown(): 已添加的任务会继续执行完毕,但是不会阻塞;新任务无法继续添加
-
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.
This method does not wait for previously submitted tasks to complete execution. Use
awaitTermination
to do that.
public List<Runnable> shutdownNow(): 在调用shutdownNow()
方法后,线程池会立即关闭,未执行的任务会以列表的形式返回。
Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution. These tasks are drained (removed) from the task queue upon return from this method.
This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.
There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. This implementation cancels tasks via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.
awaitTermination
shutdownNow
shutdown: 原有任务继续执行完毕,新任务无法继续执行