admin管理员组文章数量:1434381
My thread pool throws rejection exception when it is not full Thread pool parameter settings:
- corePoolSize:1024
- maximumPoolSize:1024
- workQueue:LinkedBlockingQueue
- queueSize:1024
- RejectedExecutionHandler:throw RejectedExecutionException Exception:
Thread pool is EXHAUSTED! Thread Name: xxx, Pool Size: 1024 (active: 93, core: 1024, max: 1024, largest: 1024), Task: 10414879419 (completed: 10414878332), Executor status:(isShutdown:false, isTerminated:false, isTerminating:false, queue:[{}])
Rejection exception thrown during thread pool operation. However, the thread pool monitoring panel and exception logs show that the number of core threads and the blocking queue length of the thread pool are both less than 100.
The exception is thrown at line 1355. It seems that adding a new task to the blocking queue failed. However, the size of the blocking queue at this time is less than 100, and the capacity is 1024. Why does calling the offer()
method fail?
public void execute(Runnable command) {
if (command == null)
throw new NullPointerException();
/*
* Proceed in 3 steps:
*
* 1. If fewer than corePoolSize threads are running, try to
* start a new thread with the given command as its first
* task. The call to addWorker atomically checks runState and
* workerCount, and so prevents false alarms that would add
* threads when it shouldn't, by returning false.
*
* 2. If a task can be successfully queued, then we still need
* to double-check whether we should have added a thread
* (because existing ones died since last checking) or that
* the pool shut down since entry into this method. So we
* recheck state and if necessary roll back the enqueuing if
* stopped, or start a new thread if there are none.
*
* 3. If we cannot queue task, then we try to add a new
* thread. If it fails, we know we are shut down or saturated
* and so reject the task.
*/
int c = ctl.get();
if (workerCountOf(c) < corePoolSize) {
if (addWorker(command, true))
return;
c = ctl.get();
}
if (isRunning(c) && workQueue.offer(command)) {
int recheck = ctl.get();
if (! isRunning(recheck) && remove(command))
reject(command);
else if (workerCountOf(recheck) == 0)
addWorker(null, false);
}
else if (!addWorker(command, false))
reject(command);
}
Why does the thread pool blocking queue throw a rejection exception when it is not full?
Why does the offer()
method return false when the blocking queue is not full?
本文标签:
版权声明:本文标题:java - The blocking queue of the thread pool is not full, but a rejection exception is thrown - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745621311a2666699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论