Add auto-configuration support for TaskExecutor

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

If no custom `Executor` bean is present, `@EnableAsync` now uses the
auto-configure application task executor. Same goes for the async support
in Spring MVC.

Closes gh-1563
This commit is contained in:
Stephane Nicoll
2018-08-02 13:36:07 +02:00
parent 193b2f187b
commit c071f34a4a
13 changed files with 1108 additions and 1 deletions

View File

@@ -160,6 +160,13 @@ content into your application. Rather, pick only the properties that you need.
spring.sendgrid.proxy.host= # SendGrid proxy host.
spring.sendgrid.proxy.port= # SendGrid proxy port.
# TASK EXECUTION ({sc-spring-boot-autoconfigure}/task/TaskProperties.{sc-ext}[TaskProperties])
spring.task.pool.allow-core-thread-timeout=true # Whether core threads are allowed to time out. This enables dynamic growing and shrinking of the pool.
spring.task.pool.core-size=8 # Core number of threads.
spring.task.pool.keep-alive=60s # Time limit for which threads may remain idle before being terminated.
spring.task.pool.max-size= # Maximum allowed number of threads. If tasks are filling up the queue, the pool can expand up to that size to accommodate the load. Ignored if the queue is unbounded.
spring.task.pool.queue-capacity= # Queue capacity. A unbounded capacity does not increase the pool and therefore ignores the "max-size" parameter.
spring.task.thread-name-prefix=executor- # Prefix to use for the names of newly created threads.
# ----------------------------------------
# WEB PROPERTIES

View File

@@ -6080,6 +6080,32 @@ in a similar manner, as shown in the following example:
[[boot-features-task-execution]]
== Task Execution
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
processing.
The thread pool uses 8 core threads that can grow and shrink according to the load. Those
default settings can be fine-tuned using the `spring.task` namespace as shown in the
following example:
[source,properties,indent=0]
----
spring.task.pool.max-threads=16
spring.task.pool.queue-capacity=100
spring.task.pool.keep-alive=10s
----
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 well as threads are reclaimed when they are idle for 10 seconds (rather than
60 seconds by default).
[[boot-features-integration]]
== Spring Integration
Spring Boot offers several conveniences for working with {spring-integration}[Spring