Skip to content

Introduce SimpleAsyncTaskScheduler with virtual threads support (as an alternative to ThreadPoolTaskScheduler) #30956

New issue

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

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

Already on GitHub? # to your account

Closed
jhoeller opened this issue Jul 26, 2023 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@jhoeller
Copy link
Contributor

jhoeller commented Jul 26, 2023

Following up on the 6.1 M1 virtual threads support (#30241) and the 6.1 M2 executor/scheduler revision (#30831, #27090, #24497), we are going to introduce a SimpleAsyncTaskScheduler in 6.1 M4. This is an extension of SimpleAsyncTaskExecutor which inherits the setVirtualThreads(true) capability (and also its configurable concurrency limit) and - when configured that way - uses a single virtual thread for scheduling and and a separate individual virtual thread per scheduled task execution. This is effectively a @Scheduled @Async like execution model but baked into a scheduler implementation, avoiding any pool setup and adhering to the general thread-per-task model of virtual threads.

As a side effect, a SimpleAsyncTaskScheduler can serve as a fully capable replacement for a SimpleAsyncTaskExecutor, e.g. as a single shared instance serving as a TaskExecutor as well as a TaskScheduler. This is generally not the case with other executor/scheduler implementations which tend to have specific constraints for the scheduler thread pool, requiring a separate thread pool for general executor purposes in practice: compare e.g. ThreadPoolTaskExecutor versus ThreadPoolTaskScheduler`.

As an alternative to the built-in thread-per-task capability, SimpleAsyncTaskScheduler can also be configured with a separate target executor for scheduled task execution through setTargetTaskExecutor: e.g. pointing to a shared ThreadPoolTaskExecutor bean. This is still rather different from a ThreadPoolTaskScheduler setup since it always uses a single scheduler thread while dynamically dispatching to the target thread pool which may have a dynamic core/max pool size range, participating in a shared concurrency limit (for explicitly submitted tasks as well as scheduled tasks, all bound by the same executor max pool size).

@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Jul 26, 2023
@jhoeller jhoeller added this to the 6.1.0-M4 milestone Jul 26, 2023
@jhoeller jhoeller self-assigned this Jul 26, 2023
@jhoeller jhoeller changed the title Introduce SimpleAsyncTaskScheduler Introduce SimpleAsyncTaskScheduler with virtual threads support (as an alternative to ThreadPoolTaskScheduler) Aug 7, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant