SimpleAsyncTaskExecutor blocks calling thread when concurrencyLimit set #33873
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: documentation
A documentation task
Milestone
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.
The text was updated successfully, but these errors were encountered: