Skip to content

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

Closed
@jhoeller

Description

@jhoeller

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).

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions