Skip to content
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

SimpleAsyncTaskExecutor blocks calling thread when concurrencyLimit set #33873

Closed
Sheikah45 opened this issue Nov 13, 2024 · 0 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task
Milestone

Comments

@Sheikah45
Copy link

The current documentation of setConcurrencyLimit of SimpleAsyncTaskExecutor suggests that it is equivalent to setting the max pool size of a thread pool task executor. However there is a difference in the implementation that for the SimpleAsyncTaskExecutor when the concurrencyLimit is reached the execute method blocks the calling thread until the number of runniing tasks is below the concurrency limit.

This is fairly non-intuitive as one would not expect an AsyncExecutor to block the calling thread when submitting a task. This is especially pertinent since the SimpleAsyncTaskExecutor is commonly used with virtual threads. The setConcurrencyLimit is the obvious way to control the number of concurrent tasks being executed but due to the blocking nature can actually be non-optimal. Instead the best way seems to be to use a Task Decorator that wraps the tasks to acquire a semaphore.

Because of this I believe it would be best to document the calling-thread blockiing behavior of the execute method when a concurrencyLimit is set on the SimpleAsyncTaskExecutor so that any users are well aware of the behavior and it is not documented as far as I can tell.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 13, 2024
@jhoeller jhoeller added type: documentation A documentation task in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 13, 2024
@jhoeller jhoeller self-assigned this Nov 13, 2024
@jhoeller jhoeller added this to the 6.1.15 milestone Nov 13, 2024
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) type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

3 participants