Skip to content

Commit 73c0634

Browse files
committed
Update WebMvc docs on use of AsyncTaskExecutor
Closes gh-30905
1 parent 4becce1 commit 73c0634

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

framework-docs/modules/ROOT/pages/web/webmvc/mvc-ann-async.adoc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Kotlin::
9292
======
9393

9494
The return value can then be obtained by running the given task through the
95-
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-configuration-spring-mvc[configured] `TaskExecutor`.
95+
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-configuration-spring-mvc[configured] `AsyncTaskExecutor`.
9696

9797

9898

@@ -128,7 +128,7 @@ Here is a very concise overview of Servlet asynchronous request processing:
128128

129129
* The controller returns a `Callable`.
130130
* Spring MVC calls `request.startAsync()` and submits the `Callable` to
131-
a `TaskExecutor` for processing in a separate thread.
131+
an `AsyncTaskExecutor` for processing in a separate thread.
132132
* Meanwhile, the `DispatcherServlet` and all filters exit the Servlet container thread,
133133
but the response remains open.
134134
* Eventually the `Callable` produces a result, and Spring MVC dispatches the request back
@@ -404,11 +404,10 @@ TIP: Spring MVC supports Reactor and RxJava through the
404404

405405
For streaming to the response, reactive back pressure is supported, but writes to the
406406
response are still blocking and are run on a separate thread through the
407-
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-configuration-spring-mvc[configured] `TaskExecutor`, to avoid
408-
blocking the upstream source (such as a `Flux` returned from `WebClient`).
409-
By default, `SimpleAsyncTaskExecutor` is used for the blocking writes, but that is not
410-
suitable under load. If you plan to stream with a reactive type, you should use the
411-
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-configuration-spring-mvc[MVC configuration] to configure a task executor.
407+
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-configuration-spring-mvc[configured]
408+
`AsyncTaskExecutor`, to avoid blocking the upstream source such as a `Flux` returned
409+
from `WebClient`.
410+
412411

413412

414413

@@ -494,7 +493,7 @@ In `web.xml` configuration, you can add `<async-supported>true</async-supported>
494493
[[mvc-ann-async-configuration-spring-mvc]]
495494
=== Spring MVC
496495

497-
The MVC configuration exposes the following options related to asynchronous request processing:
496+
The MVC configuration exposes the following options for asynchronous request processing:
498497

499498
* Java configuration: Use the `configureAsyncSupport` callback on `WebMvcConfigurer`.
500499
* XML namespace: Use the `<async-support>` element under `<mvc:annotation-driven>`.
@@ -504,10 +503,9 @@ You can configure the following:
504503
* Default timeout value for async requests, which if not set, depends
505504
on the underlying Servlet container.
506505
* `AsyncTaskExecutor` to use for blocking writes when streaming with
507-
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-reactive-types[Reactive Types] and for executing `Callable` instances returned from
508-
controller methods. We highly recommended configuring this property if you
509-
stream with reactive types or have controller methods that return `Callable`, since
510-
by default, it is a `SimpleAsyncTaskExecutor`.
506+
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-reactive-types[Reactive Types] and for
507+
executing `Callable` instances returned from controller methods.
508+
The one used by default is not suitable for production under load.
511509
* `DeferredResultProcessingInterceptor` implementations and `CallableProcessingInterceptor` implementations.
512510

513511
Note that you can also set the default timeout value on a `DeferredResult`,

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import java.util.concurrent.Callable;
2323

2424
import org.springframework.core.task.AsyncTaskExecutor;
25-
import org.springframework.core.task.SimpleAsyncTaskExecutor;
2625
import org.springframework.lang.Nullable;
27-
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
2826
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
2927
import org.springframework.web.context.request.async.DeferredResult;
3028
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
@@ -49,15 +47,15 @@ public class AsyncSupportConfigurer {
4947

5048

5149
/**
52-
* The provided task executor is used to:
50+
* The provided task executor is used for the following:
5351
* <ol>
5452
* <li>Handle {@link Callable} controller method return values.
5553
* <li>Perform blocking writes when streaming to the response
5654
* through a reactive (e.g. Reactor, RxJava) controller method return value.
5755
* </ol>
58-
* <p>By default only a {@link SimpleAsyncTaskExecutor} is used. However when
59-
* using the above two use cases, it's recommended to configure an executor
60-
* backed by a thread pool such as {@link ThreadPoolTaskExecutor}.
56+
* <p>If your application has controllers with such return types, please
57+
* configure an {@link AsyncTaskExecutor} as the one used by default is not
58+
* suitable for production under load.
6159
* @param taskExecutor the task executor instance to use by default
6260
*/
6361
public AsyncSupportConfigurer setTaskExecutor(AsyncTaskExecutor taskExecutor) {

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ public WebBindingInitializer getWebBindingInitializer() {
399399
* Set the default {@link AsyncTaskExecutor} to use when a controller method
400400
* return a {@link Callable}. Controller methods can override this default on
401401
* a per-request basis by returning an {@link WebAsyncTask}.
402-
* <p>By default a {@link SimpleAsyncTaskExecutor} instance is used.
403-
* It's recommended to change that default in production as the simple executor
404-
* does not re-use threads.
402+
* <p>If your application has controllers with such return types, please
403+
* configure an {@link AsyncTaskExecutor} as the one used by default is not
404+
* suitable for production under load.
405405
*/
406406
public void setTaskExecutor(AsyncTaskExecutor taskExecutor) {
407407
this.taskExecutor = taskExecutor;

0 commit comments

Comments
 (0)