Auto-configure SimpleAsyncTaskScheduler when virtual threads are enabled

This auto-configures a new SimpleAsyncTaskSchedulerBuilder bean in the
context. This bean is configured to use virtual threads, if enabled.

SimpleAsyncTaskSchedulerCustomizers can be used to customize the built
SimpleAsyncTaskScheduler.

If virtual threads are enabled, the application task scheduler is
configured to be a SimpleAsyncTaskScheduler.

Adds a new configuration property spring.task.scheduling.simple
.concurrency-limit

Closes gh-36609
This commit is contained in:
Moritz Halbritter
2023-08-01 15:00:44 +02:00
parent 3c12f39adb
commit 5b00d5f89b
8 changed files with 509 additions and 7 deletions

View File

@@ -36,8 +36,11 @@ Those default settings can be fine-tuned using the `spring.task.execution` names
This changes the thread pool to use a bounded queue so that when the queue is full (100 tasks), the thread pool increases to maximum 16 threads.
Shrinking of the pool is more aggressive as threads are reclaimed when they are idle for 10 seconds (rather than 60 seconds by default).
A `ThreadPoolTaskScheduler` can also be auto-configured if need to be associated to scheduled task execution (using `@EnableScheduling` for instance).
The thread pool uses one thread by default and its settings can be fine-tuned using the `spring.task.scheduling` namespace, as shown in the following example:
A scheduler can also be auto-configured if need to be associated to scheduled task execution (using `@EnableScheduling` for instance).
When virtual threads are enabled (using Java 21+ and configprop:spring.threads.virtual.enabled[] set to `true`) this will be a `SimpleAsyncTaskScheduler` that uses virtual threads.
Otherwise, it will be a `ThreadPoolTaskScheduler` with sensible defaults.
The `ThreadPoolTaskScheduler` uses one thread by default and its settings can be fine-tuned using the `spring.task.scheduling` namespace, as shown in the following example:
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
@@ -49,5 +52,5 @@ The thread pool uses one thread by default and its settings can be fine-tuned us
size: 2
----
A `ThreadPoolTaskExecutorBuilder` bean, a `SimpleAsyncTaskExecutorBuilder` bean and a `ThreadPoolTaskSchedulerBuilder` bean are made available in the context if a custom executor or scheduler needs to be created.
The `SimpleAsyncTaskExecutorBuilder` is auto-configured to use virtual threads if they are enabled (using Java 21+ and configprop:spring.threads.virtual.enabled[] set to `true`).
A `ThreadPoolTaskExecutorBuilder` bean, a `SimpleAsyncTaskExecutorBuilder` bean, a `ThreadPoolTaskSchedulerBuilder` bean and a `SimpleAsyncTaskSchedulerBuilder` are made available in the context if a custom executor or scheduler needs to be created.
The `SimpleAsyncTaskExecutorBuilder` and `SimpleAsyncTaskSchedulerBuilder` beans are auto-configured to use virtual threads if they are enabled (using Java 21+ and configprop:spring.threads.virtual.enabled[] set to `true`).