Add auto-configuration support for TaskScheduler

This commit adds support for providing a default ThreadPoolTaskScheduler
with sensible defaults. A new TaskSchedulerBuilder is provided with
defaults from the `spring.task.scheduler.*` namespace and can be used
to create custom instances.

If no custom `TaskScheduler` bean is present, `@EnableScheduling` now
uses the auto-configured task scheduler.

Closes gh-1397
This commit is contained in:
Stephane Nicoll
2018-08-08 14:30:42 +02:00
parent dcd80c087e
commit de470540ea
11 changed files with 675 additions and 7 deletions

View File

@@ -169,6 +169,10 @@ content into your application. Rather, pick only the properties that you need.
spring.task.execution.pool.queue-capacity= # Queue capacity. An unbounded capacity does not increase the pool and therefore ignores the "max-size" property.
spring.task.execution.thread-name-prefix=task- # Prefix to use for the names of newly created threads.
# TASK SCHEDULING ({sc-spring-boot-autoconfigure}/task/TaskSchedulingProperties.{sc-ext}[TaskSchedulingProperties])
spring.task.scheduling.pool.size=1 # Maximum allowed number of threads.
spring.task.scheduling.thread-name-prefix=scheduling- # Prefix to use for the names of newly created threads.
# ----------------------------------------
# WEB PROPERTIES
# ----------------------------------------

View File

@@ -6138,8 +6138,8 @@ in a similar manner, as shown in the following example:
[[boot-features-task-execution]]
== Task Execution
[[boot-features-task-execution-scheduling]]
== Task Execution and Scheduling
In the absence of a `TaskExecutor` bean in the context, Spring Boot auto-configures a
`ThreadPoolTaskExecutor` with sensible defaults that can be automatically associated to
asynchronous task execution (`@EnableAsync`) and Spring MVC asynchronous request
@@ -6161,6 +6161,12 @@ tasks), the thread pool increases to maximum 16 threads. Shrinking of the pool i
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 to be associated to
scheduled task execution (`@EnableScheduling`). The thread pool uses one thread by default
and those settings can be fine-tuned using the `spring.task.scheduling` namespace.
Both a `TaskExecutorBuilder` and `TaskSchedulerBuilder` bean are made available in the
context if a custom executor or scheduler needs to be created.