Настройки параметров пула потоков:
- corePoolSize: 1024
- maximumPoolSize: 1024
- workQueue: LinkedBlockingQueue
- queueSize: 1024
- RejectedExecutionHandler: выдать исключение 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:[{}])
Исключение выдается в строке 1355. Похоже, не удалось добавить новую задачу в очередь блокировки. Однако размер очереди блокировки в это время меньше 100, а емкость — 1024. Почему вызов метода Offer() завершается неудачно?
Код: Выделить всё
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);
}
Почему метод Offer() вернуть false, если очередь блокировки не заполнена?
Подробнее здесь: https://stackoverflow.com/questions/791 ... ception-is
Мобильная версия