java多线程执行任务,并显式构造 ThreadPoolExecutor
就像下面一样
final ExecutorService threadPool = new ThreadPoolExecutor(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1), myRejectedExecutionHandler);
并通过下面的方式提交任务
for (int i = 0; i < count; i++) {
int articleId = i;
CompletableFuture.supplyAsync(() -> articleId, threadPool);
}
现在我想定制 rejectedExecutionHandler
```
void rejectedExecution(Runnable r, ThreadPoolExecutor executor);
但我怎么才能拿到证件?因为我想登录被拒绝的articleid `rejectedExecution` 例如
log.warn("article: {} is rejected, please process it manually", articleId);
1条答案
按热度按时间6za6bjd01#
我的解决方案是:不使用自定义rejectedexecutionhandler并捕获rejectedexecutionexception