java - ThreadPoolExecutor.CallerRunsPolicy 会抛出 RejectedExecutionException 吗?

标签 java threadpool executor

是否有任何情况下 ThreadPoolExecutor.CallerRunsPolicy会抛出 RejectedExecutionException

在我看来,政策本身就是为了防止抛出这些异常。其接口(interface)方法的 API,RejectedExecutionHandler.rejectedExecution()声称它可能会抛出 RejectedExecutionException . CallerRunsPolicy.rejectedExecution() 的 API 没有。

总结:我需要显式处理 RejectedExecutionException 吗?在 execute()如果我使用 CallerRunsPolicy

最佳答案

不,你不知道。 ThreadPoolExecutor.CallerRunsPolicy 永远不会抛出 RejectedExecutionException 除非你在 Runnable#run

下明确抛出它

关于java - ThreadPoolExecutor.CallerRunsPolicy 会抛出 RejectedExecutionException 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3737004/

相关文章:

java - 使用不同的唯一 id 提高每个线程的性能

c# - 优先考虑线程。

java - executor.invokeAll() lambda 体不返回

java - 比较并设置Java操作

java - Java (Android) 中的 List<?> 是什么?

java - RestAssured Oauth 登录 Twitter 的问题

hibernate - 使用 Grails Execector 插件的 runAsync ,为什么我需要事务来保存域对象?

Java Swing revalidate() 和 repaint() 问题

c++ - 如何更改 boost 线程限制?

spring - grails executor plugin - executorService 注入(inject)