Skip to content

Doc: ThreadPoolTaskExecutor's defaults vs setting queueCapacity for common pool scenarios [SPR-16944] #21483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jun 15, 2018 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 15, 2018

Constantino Cronemberger opened SPR-16944 and commented

According to ThreadPoolExecutor Javadoc:

"If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full."

In the class ThreadPoolTaskExecutor the default values are: 1 for the corePoolSize and Integer.MAX_VALUE for maxPoolSize and queueCapacity.

This means that a second thread will be created only when we have MAX_VALUE elements in the queue. This is is not reasonable.

I think queueCapacity should not have a default value.


Issue Links:

Backported to: 4.3.19

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Those defaults essentially mimic Executors.newFixedThreadPool(1) / Executors.newSingleThreadExecutor(), sharing a single pooled thread for all tasks. The unbounded maxPoolSize may appear odd here (since it is behaviorally equivalent to a maximum of 1); that setting is primarily there in case of a custom queueCapacity, providing scaling by default at that point (without setting a custom maxPoolSize at the same time).

Making the default queueCapacity 0 and therefore not allowing for any queued tasks would mimic Executors.newCachedThreadPool(), with immediate scaling of threads in the pool to a potentially very high number. While this is not unreasonable in many scenarios, the fixed single thread seems to be safer default. As outlined above, enabling this mode of operation just requires setting queueCapacity to 0, without touching the maxPoolSize setting.

I'll therefore turn this into a documentation task, making those typical scenarios clearer.

@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0.8 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants