Polish "Update documentation for Task Execution"
See gh-44926
This commit is contained in:
@@ -14,67 +14,54 @@ The auto-configured javadoc:org.springframework.core.task.AsyncTaskExecutor[] is
|
|||||||
- Utilized for inbound and outbound message channels in Spring WebSocket.
|
- Utilized for inbound and outbound message channels in Spring WebSocket.
|
||||||
- Acts as a bootstrap executor for JPA, based on the bootstrap mode of JPA repositories.
|
- Acts as a bootstrap executor for JPA, based on the bootstrap mode of JPA repositories.
|
||||||
|
|
||||||
While this approach works in most scenarios, Spring Boot allows you to override the auto-configured
|
While this approach works in most scenarios, Spring Boot allows you to override the auto-configured javadoc:org.springframework.core.task.AsyncTaskExecutor[].
|
||||||
javadoc:org.springframework.core.task.AsyncTaskExecutor[].
|
By default, when a custom javadoc:java.util.concurrent.Executor[] bean is registered, the auto-configured javadoc:org.springframework.core.task.AsyncTaskExecutor[] backs off, and the custom javadoc:java.util.concurrent.Executor[] is used for regular task execution (via javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation]).
|
||||||
By default, when a custom javadoc:java.util.concurrent.Executor[] bean is registered, the auto-configured
|
|
||||||
javadoc:org.springframework.core.task.AsyncTaskExecutor[] steps aside, and the custom javadoc:java.util.concurrent.Executor[] is used for regular task execution (via javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation]).
|
|
||||||
|
|
||||||
However, Spring MVC, Spring WebFlux, and Spring GraphQL all require a bean named `applicationTaskExecutor`.
|
However, Spring MVC, Spring WebFlux, and Spring GraphQL all require a bean named `applicationTaskExecutor`.
|
||||||
For Spring MVC and Spring WebFlux, this bean must be of type javadoc:org.springframework.core.task.AsyncTaskExecutor[], whereas Spring GraphQL does not enforce this type requirement.
|
For Spring MVC and Spring WebFlux, this bean must be of type javadoc:org.springframework.core.task.AsyncTaskExecutor[], whereas Spring GraphQL does not enforce this type requirement.
|
||||||
|
|
||||||
Spring WebSocket and JPA will use javadoc:org.springframework.core.task.AsyncTaskExecutor[] if either a single bean of this type is available or a bean named `applicationTaskExecutor` is defined.
|
Spring WebSocket and JPA will use javadoc:org.springframework.core.task.AsyncTaskExecutor[] if either a single bean of this type is available or a bean named `applicationTaskExecutor` is defined.
|
||||||
|
|
||||||
The following code snippet demonstrates how to register a custom javadoc:org.springframework.core.task.AsyncTaskExecutor[]
|
The following code snippet demonstrates how to register a custom javadoc:org.springframework.core.task.AsyncTaskExecutor[] to be used with Spring MVC, Spring WebFlux, Spring GraphQL, Spring WebSocket and JPA.
|
||||||
to be used with Spring MVC, Spring WebFlux, Spring GraphQL, Spring WebSocket and JPA.
|
|
||||||
|
|
||||||
include-code::TaskExecutionConfigurationExamples[tag=application-task-executor]
|
include-code::TaskExecutionConfigurationExamples[tag=application-task-executor]
|
||||||
|
|
||||||
[NOTE]
|
[NOTE]
|
||||||
====
|
====
|
||||||
The `applicationTaskExecutor` bean will also be used for regular task execution if there is no
|
The `applicationTaskExecutor` bean will also be used for regular task execution if there is no javadoc:org.springframework.context.annotation.Primary[format=annotation] bean or a bean named `taskExecutor` of type javadoc:java.util.concurrent.Executor[] or javadoc:org.springframework.scheduling.annotation.AsyncConfigurer[] present in the application context.
|
||||||
javadoc:org.springframework.context.annotation.Primary[format=annotation] bean or a bean named `taskExecutor` of type javadoc:java.util.concurrent.Executor[]
|
|
||||||
or javadoc:org.springframework.scheduling.annotation.AsyncConfigurer[] present in the application context.
|
|
||||||
====
|
====
|
||||||
|
|
||||||
[WARNING]
|
[WARNING]
|
||||||
====
|
====
|
||||||
If neither the auto-configured `AsyncTaskExecutor` nor the `applicationTaskExecutor` bean is defined, the application defaults to a bean named `taskExecutor` for regular task execution (javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation]), following Spring Framework's behavior.
|
If neither the auto-configured `AsyncTaskExecutor` nor the `applicationTaskExecutor` bean is defined, the application defaults to a bean named `taskExecutor` for regular task execution (javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation]), following Spring Framework's behavior.
|
||||||
However, this bean will not be used for Spring MVC, Spring WebFlux, Spring GraphQL.
|
However, this bean will not be used for Spring MVC, Spring WebFlux, Spring GraphQL.
|
||||||
It could, however, be used for Spring WebSocket or JPA if bean's type is javadoc:org.springframework.core.task.AsyncTaskExecutor[].
|
It could, however, be used for Spring WebSocket or JPA if the bean's type is javadoc:org.springframework.core.task.AsyncTaskExecutor[].
|
||||||
====
|
====
|
||||||
|
|
||||||
If your application needs multiple `Executor` beans for different integrations, such as one for regular task execution with javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation]
|
If your application needs multiple `Executor` beans for different integrations, such as one for regular task execution with javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation] and other for Spring MVC, Spring WebFlux, Spring WebSocket and JPA, you can configure them as follows.
|
||||||
and other for Spring MVC, Spring WebFlux, Spring WebSocket and JPA you can configure them as follows.
|
|
||||||
|
|
||||||
include-code::TaskExecutionConfigurationExamples[tag=multiple-task-executor]
|
include-code::TaskExecutionConfigurationExamples[tag=multiple-task-executor]
|
||||||
|
|
||||||
[TIP]
|
[TIP]
|
||||||
====
|
====
|
||||||
The auto-configured javadoc:org.springframework.boot.task.ThreadPoolTaskExecutorBuilder[] or
|
The auto-configured javadoc:org.springframework.boot.task.ThreadPoolTaskExecutorBuilder[] or javadoc:org.springframework.boot.task.SimpleAsyncTaskExecutorBuilder[] allow you to easily create instances of type javadoc:org.springframework.core.task.AsyncTaskExecutor[] that replicate the default behavior of auto-configuration.
|
||||||
javadoc:org.springframework.boot.task.SimpleAsyncTaskExecutorBuilder[] allow you to easily create instances of type javadoc:org.springframework.core.task.AsyncTaskExecutor[] that replicate the default behavior of auto-configuration.
|
|
||||||
|
|
||||||
include-code::TaskExecutionConfigurationExamples[tag=executor-builder]
|
include-code::TaskExecutionConfigurationExamples[tag=executor-builder]
|
||||||
====
|
====
|
||||||
|
|
||||||
If a `taskExecutor` named bean is not an option, you can mark your bean as javadoc:org.springframework.context.annotation.Primary[format=annotation] or define an
|
If a `taskExecutor` named bean is not an option, you can mark your bean as javadoc:org.springframework.context.annotation.Primary[format=annotation] or define an javadoc:org.springframework.scheduling.annotation.AsyncConfigurer[] bean to specify the `Executor` responsible for handling regular task execution with javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation].
|
||||||
javadoc:org.springframework.scheduling.annotation.AsyncConfigurer[] bean to specify the
|
|
||||||
`Executor` responsible for handling regular task execution with javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation].
|
|
||||||
The following example demonstrates how to achieve this.
|
The following example demonstrates how to achieve this.
|
||||||
|
|
||||||
include-code::TaskExecutionConfigurationExamples[tag=async-configurer]
|
include-code::TaskExecutionConfigurationExamples[tag=async-configurer]
|
||||||
|
|
||||||
To register a custom javadoc:java.util.concurrent.Executor[] while keeping the auto-configured
|
To register a custom javadoc:java.util.concurrent.Executor[] while keeping the auto-configured javadoc:org.springframework.core.task.AsyncTaskExecutor[], you can create a custom javadoc:java.util.concurrent.Executor[] bean and set the `defaultCandidate=false` attribute in its javadoc:org.springframework.context.annotation.Bean[format=annotation] annotation, as demonstrated in the following example:
|
||||||
javadoc:org.springframework.core.task.AsyncTaskExecutor[], you can create a custom
|
|
||||||
javadoc:java.util.concurrent.Executor[] bean and set the `defaultCandidate=false` attribute in its
|
|
||||||
javadoc:org.springframework.context.annotation.Bean[format=annotation] annotation, as demonstrated in the following example:
|
|
||||||
|
|
||||||
include-code::TaskExecutionConfigurationExamples[tag=default-candidate-task-executor]
|
include-code::TaskExecutionConfigurationExamples[tag=default-candidate-task-executor]
|
||||||
|
|
||||||
In that case, you will be able to javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation]
|
In that case, you will be able to autowire your custom javadoc:java.util.concurrent.Executor[] into other components while retaining the auto-configured javadoc:org.springframework.core.task.AsyncTaskExecutor[].
|
||||||
your custom javadoc:java.util.concurrent.Executor[] into other components while retaining the auto-configured `AsyncTaskExecutor`.
|
|
||||||
However, remember to use the javadoc:org.springframework.beans.factory.annotation.Qualifier[format=annotation] annotation alongside javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation].
|
However, remember to use the javadoc:org.springframework.beans.factory.annotation.Qualifier[format=annotation] annotation alongside javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation].
|
||||||
|
|
||||||
If for some reason, it is not possible, you can request Spring Boot to auto-configure an `AsyncTaskExecutor` anyway, as follows:
|
If this is not possible for you, you can request Spring Boot to auto-configure an javadoc:org.springframework.core.task.AsyncTaskExecutor[] anyway, as follows:
|
||||||
|
|
||||||
[configprops,yaml]
|
[configprops,yaml]
|
||||||
----
|
----
|
||||||
|
|||||||
Reference in New Issue
Block a user