Skip to content

Commit 06f6991

Browse files
committed
Polishing contribution
Closes gh-34885
1 parent d9459bd commit 06f6991

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
Spring MVC has an extensive integration with Servlet asynchronous request
55
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-processing[processing]:
66

7-
* xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-deferredresult[`DeferredResult`],xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-callable[`Callable`] and xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-webasynctask[`WebAsyncTask`](holder/wrapper for Callable)
8-
return values in controller methods provide basic support for a single asynchronous
9-
return value.
7+
* xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-deferredresult[`DeferredResult`],
8+
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-callable[`Callable`], and
9+
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-webasynctask[`WebAsyncTask`] return values
10+
in controller methods provide support for a single asynchronous return value.
1011
* Controllers can xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-http-streaming[stream] multiple values, including
11-
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-sse[SSE] and xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-output-stream[raw data].
12+
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-sse[SSE] and
13+
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-output-stream[raw data].
1214
* Controllers can use reactive clients and return
1315
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-reactive-types[reactive types] for response handling.
1416

@@ -96,10 +98,14 @@ xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-configuration-spring-mvc[config
9698

9799

98100

101+
99102
[[mvc-ann-async-webasynctask]]
100103
== `WebAsyncTask`
101104

102-
`WebAsyncTask` is a holder/wrapper for a `java.util.concurrent.Callable` that allows you to set a custom asynchronous request timeout value and a custom `AsyncTaskExecutor` for executing the `java.util.concurrent.Callable` if you want to use a different `AsyncTaskExecutor` than the default one used by Spring MVC. Below is an example of using `WebAsyncTask`:
105+
`WebAsyncTask` is comparable to using xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-callable[Callable]
106+
but allows customizing additional settings such a request timeout value, and the
107+
`AsyncTaskExecutor` to execute the `java.util.concurrent.Callable` with instead
108+
of the defaults set up globally for Spring MVC. Below is an example of using `WebAsyncTask`:
103109

104110
[tabs]
105111
======
@@ -108,9 +114,9 @@ Java::
108114
[source,java,indent=0,subs="verbatim,quotes"]
109115
----
110116
@GetMapping("/callable")
111-
WebAsyncTask<String> asynchronousRequestProcessingWithCallableWrappedInaWebAsyncTask() {
117+
WebAsyncTask<String> handle() {
112118
return new WebAsyncTask<String>(20000L,()->{
113-
Thread.sleep(10000); //simulate long running task
119+
Thread.sleep(10000); //simulate long-running task
114120
return "asynchronous request completed";
115121
});
116122
}
@@ -121,7 +127,7 @@ Kotlin::
121127
[source,kotlin,indent=0,subs="verbatim,quotes"]
122128
----
123129
@GetMapping("/callable")
124-
fun asynchronousRequestProcessingWithCallableWrappedInWebAsyncTask(): WebAsyncTask<String> {
130+
fun handle(): WebAsyncTask<String> {
125131
return WebAsyncTask(20000L) {
126132
Thread.sleep(10000) // simulate long-running task
127133
"asynchronous request completed"
@@ -132,6 +138,7 @@ fun asynchronousRequestProcessingWithCallableWrappedInWebAsyncTask(): WebAsyncTa
132138

133139

134140

141+
135142
[[mvc-ann-async-processing]]
136143
== Processing
137144

0 commit comments

Comments
 (0)