Skip to content

Commit cfecdfc

Browse files
committed
Polish "Update documentation for Task Execution"
See gh-44926
1 parent 6a92364 commit cfecdfc

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/task-execution-and-scheduling.adoc

+11-24
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,54 @@ The auto-configured javadoc:org.springframework.core.task.AsyncTaskExecutor[] is
1414
- Utilized for inbound and outbound message channels in Spring WebSocket.
1515
- Acts as a bootstrap executor for JPA, based on the bootstrap mode of JPA repositories.
1616

17-
While this approach works in most scenarios, Spring Boot allows you to override the auto-configured
18-
javadoc:org.springframework.core.task.AsyncTaskExecutor[].
19-
By default, when a custom javadoc:java.util.concurrent.Executor[] bean is registered, the auto-configured
20-
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]).
17+
While this approach works in most scenarios, Spring Boot allows you to override the auto-configured javadoc:org.springframework.core.task.AsyncTaskExecutor[].
18+
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]).
2119

2220
However, Spring MVC, Spring WebFlux, and Spring GraphQL all require a bean named `applicationTaskExecutor`.
2321
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.
2422

2523
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.
2624

27-
The following code snippet demonstrates how to register a custom javadoc:org.springframework.core.task.AsyncTaskExecutor[]
28-
to be used with Spring MVC, Spring WebFlux, Spring GraphQL, Spring WebSocket and JPA.
25+
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.
2926

3027
include-code::TaskExecutionConfigurationExamples[tag=application-task-executor]
3128

3229
[NOTE]
3330
====
34-
The `applicationTaskExecutor` bean will also be used for regular task execution if there is no
35-
javadoc:org.springframework.context.annotation.Primary[format=annotation] bean or a bean named `taskExecutor` of type javadoc:java.util.concurrent.Executor[]
36-
or javadoc:org.springframework.scheduling.annotation.AsyncConfigurer[] present in the application context.
31+
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.
3732
====
3833

3934
[WARNING]
4035
====
4136
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.
4237
However, this bean will not be used for Spring MVC, Spring WebFlux, Spring GraphQL.
43-
It could, however, be used for Spring WebSocket or JPA if bean's type is javadoc:org.springframework.core.task.AsyncTaskExecutor[].
38+
It could, however, be used for Spring WebSocket or JPA if the bean's type is javadoc:org.springframework.core.task.AsyncTaskExecutor[].
4439
====
4540

46-
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]
47-
and other for Spring MVC, Spring WebFlux, Spring WebSocket and JPA you can configure them as follows.
41+
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.
4842

4943
include-code::TaskExecutionConfigurationExamples[tag=multiple-task-executor]
5044

5145
[TIP]
5246
====
53-
The auto-configured javadoc:org.springframework.boot.task.ThreadPoolTaskExecutorBuilder[] or
54-
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.
47+
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.
5548
5649
include-code::TaskExecutionConfigurationExamples[tag=executor-builder]
5750
====
5851

59-
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
60-
javadoc:org.springframework.scheduling.annotation.AsyncConfigurer[] bean to specify the
61-
`Executor` responsible for handling regular task execution with javadoc:org.springframework.scheduling.annotation.EnableAsync[format=annotation].
52+
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].
6253
The following example demonstrates how to achieve this.
6354

6455
include-code::TaskExecutionConfigurationExamples[tag=async-configurer]
6556

66-
To register a custom javadoc:java.util.concurrent.Executor[] while keeping the auto-configured
67-
javadoc:org.springframework.core.task.AsyncTaskExecutor[], you can create a custom
68-
javadoc:java.util.concurrent.Executor[] bean and set the `defaultCandidate=false` attribute in its
69-
javadoc:org.springframework.context.annotation.Bean[format=annotation] annotation, as demonstrated in the following example:
57+
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:
7058

7159
include-code::TaskExecutionConfigurationExamples[tag=default-candidate-task-executor]
7260

73-
In that case, you will be able to javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation]
74-
your custom javadoc:java.util.concurrent.Executor[] into other components while retaining the auto-configured `AsyncTaskExecutor`.
61+
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[].
7562
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].
7663

77-
If for some reason, it is not possible, you can request Spring Boot to auto-configure an `AsyncTaskExecutor` anyway, as follows:
64+
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:
7865

7966
[configprops,yaml]
8067
----

0 commit comments

Comments
 (0)