【发布时间】:2019-03-09 23:48:06
【问题描述】:
ThreadPoolExecutor 的构造函数将BlockingQueue 的类型参数设为Runnable。
假设我有一个像这样声明的ThreadPoolExecutor
ThreadPoolExecutor customThreadPool = new ThreadPoolExecutor(numberOfAvailableProcessors,
numberOfAvailableProcessors, 2L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
Executors.defaultThreadFactory(),
new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor threadPoolExecutor) {
// Do something here to handle it
}
});
我的问题是什么时候做类似的事情:
customThreadPool.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return Math.toIntExact(Thread.currentThread().getId());
}
})
即使我已将Queue 的类型参数指定为Runnable,ThreadPool 如何处理此问题?
此任务将如何排队?
【问题讨论】:
标签: java threadpoolexecutor callable blockingqueue