我正在使用com.google.common.util.concurrent.SimpleTimeLimiter
,
想知道这是否可以解决线程池关闭问题?我使用 noargs 构造函数 new SimpleTimeLimiter()
构建它,但这并没有提供调用 shutdown()
的方法。
最佳答案
注意 ExecutorService.shutdown() 的 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.
支持的ExecutorService.submit(callable)
将在SimpleTimeLimiter
内部被调用一次。由于不会再提交其他新任务,因此不需要 shutdown()
。
但是如果我们使用构造函数SimpleTimeLimiter(ExecutorService executor)
,那么我们就必须负责shutdown()
。
关于guava - SimpleTimeLimiter 关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15247883/