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.
*
* <p>This method does not wait for previously submitted tasks to
* complete execution. Use {@link #awaitTermination awaitTermination}
* to do that.
**/
void shutdown();
意思是继续执行前面已经提交的tasks,而不会接受新提交的任务
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.
*
* <p>This method does not wait for actively executing tasks to
* terminate. Use {@link #awaitTermination awaitTermination} to
* do that.
**/
void shutDownNow();
该方法直接停止线程池里所有的活跃线程,并且停止正在等待的线程,返回这些等待的线程列表,并且后面还说了,在方法执行的时候不会等待线程执行结束,可以调用awaitTermination方法等待