队列为空时,带有LinkedBlockingQueue的ThreaPool拒绝任务

时间:2014-11-18 03:49:54

标签: java threadpool threadpoolexecutor

我创建了一个包含以下代码的线程池

ThreadPoolExecutor backgroupTaskPool = new ThreadPoolExecutor(100, 100, 10, TimeUnit.SECONDS,  new LinkedBlockingQueue<Runnable>(100));
backgroupTaskPool.allowCoreThreadTimeOut(true);

将任务提交到此池时,它会抛出RejectedExecutionException,但池中的线程未达到maximumPoolSize且LinkedBlockingQueue为空:

Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@15e9aebd rejected from java.util.concurrent.ThreadPoolExecutor@7774348b[Shutting down, pool size = 9, active threads = 9, queued tasks = 0, completed tasks = 105]
    at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2048)
    at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:821)

你知道为什么会发生这种情况吗?

THX。

1 个答案:

答案 0 :(得分:2)

基于异常消息

Task java.util.concurrent.FutureTask@15e9aebd rejected from java.util.concurrent.ThreadPoolExecutor@7774348b[Shutting down, pool size = 9, active threads = 9, queued tasks = 0, completed tasks = 105]

您似乎正在关闭ThreadPoolExecutor。在您拨打shutdown之后,您无法提交任务。