简体   繁体   中英

ThreaPool with LinkedBlockingQueue reject task when queue is empty

I created a thread pool with following code

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

when submit tasks to this pool, it throws RejectedExecutionException, but the threads in the pool not reaches maximumPoolSize and the LinkedBlockingQueue is empty:

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)

Do you have any idea why could this happen?

THX.

Based on the exception message

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]

You seem to be shutting down the ThreadPoolExecutor . You can't submit tasks after you've called shutdown .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM