简体   繁体   English

Java文档中ExecutorService方法shutdown()的矛盾

[英]Contradiction in Java documentation for ExecutorService method shutdown()

Here is the first line in the javadoc : 这是javadoc的第一行:

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. 如果已关闭,则调用不会产生任何其他影响。

And here is the second line right beneath the previous one: 这是上一行下面的第二行:

This method does not wait for previously submitted tasks to complete execution . 此方法不等待先前提交的任务完成执行 Use awaitTermination to do that. 使用awaitTermination可以做到这一点。

So which is it? 那是什么呢? Does shutdown() wait for previously submitted tasks to be executed before shutting down or doesn't it? shutdown()是否在shutdown()之前等待先前提交的任务执行?

There is no contradiction. 没有矛盾。 The method just tells the executor "please don't accept new tasks" and returns immediately. 该方法只是告诉执行者“请不要接受新任务”并立即返回。 The thread which asked for shutdown can then keep doing something else, while the executor keeps executing the submitted tasks, in parallel. 然后,要求关闭的线程可以继续执行其他操作,而执行程序则继续并行执行提交的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM