What's Spring's default queue size with a ThreadPoolTaskExecutor?
Setting maxPoolSize
implicitly allows for tasks to get dropped.
However, the default queue capacity is Integer.MAX_VALUE
, which, for practical purposes, is infinity.
Something to watch out for is that ThreadPoolTaskExecutor
uses a ThreadPoolExecutor
underneath, which has a somewhat unusual approach to queueing, described in the docs:
If
corePoolSize
or more threads are running, the Executor always prefers queuing a request rather than adding a new thread.
This means that maxPoolSize
is only relevant when the queue is full, otherwise the number of threads will never grow beyond corePoolSize
.
As an example, if we submit tasks that never complete to the thread pool:
- the first
corePoolSize
submissions will start a new thread each; - after that, all submissions go to the queue;
- if the queue is finite and its capacity is exhausted, each submission starts a new thread, up to
maxPoolSize
; - when both the pool and the queue are full, new submissions are rejected.