【发布时间】:2018-10-13 18:11:52
【问题描述】:
我有ThreadPoolExecutorService,核心池大小为 5,最大池大小为 10。我还将队列大小设置为 0。所以当我尝试 submit 11 个任务时 - 最后一个被拒绝。对于这些情况,我使用RejectedExecutionHandler。但是,从提交者线程我无法确定 - 我的任务是提交还是拒绝。
这是来自提交者线程的代码:
public void submitToAsyncExecution(Runnable r) {
Future<Void> task = this.threadPool.submit(r)
//is it possible to use returned future object to find out if my task is rejected or not ?
}
我知道 - 替代方法是省略 RejectedExecutionHandler 并抛出拒绝异常,但是在我的情况下处理程序方法更合理。
【问题讨论】:
标签: java spring multithreading