Skip to content

Commit d9459bd

Browse files
addoDevrstoyanchev
authored andcommitted
Improve mvc-ann-async.adoc
Added section for WebAsyncTask return type along with java and kotlin example code See gh-34885 Signed-off-by: addoDev <[email protected]>
1 parent 3f0892b commit d9459bd

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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`] and xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-callable[`Callable`]
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)
88
return values in controller methods provide basic support for a single asynchronous
99
return value.
1010
* Controllers can xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-http-streaming[stream] multiple values, including
@@ -96,6 +96,42 @@ xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-configuration-spring-mvc[config
9696

9797

9898

99+
[[mvc-ann-async-webasynctask]]
100+
== `WebAsyncTask`
101+
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`:
103+
104+
[tabs]
105+
======
106+
Java::
107+
+
108+
[source,java,indent=0,subs="verbatim,quotes"]
109+
----
110+
@GetMapping("/callable")
111+
WebAsyncTask<String> asynchronousRequestProcessingWithCallableWrappedInaWebAsyncTask() {
112+
return new WebAsyncTask<String>(20000L,()->{
113+
Thread.sleep(10000); //simulate long running task
114+
return "asynchronous request completed";
115+
});
116+
}
117+
----
118+
119+
Kotlin::
120+
+
121+
[source,kotlin,indent=0,subs="verbatim,quotes"]
122+
----
123+
@GetMapping("/callable")
124+
fun asynchronousRequestProcessingWithCallableWrappedInWebAsyncTask(): WebAsyncTask<String> {
125+
return WebAsyncTask(20000L) {
126+
Thread.sleep(10000) // simulate long-running task
127+
"asynchronous request completed"
128+
}
129+
}
130+
----
131+
======
132+
133+
134+
99135
[[mvc-ann-async-processing]]
100136
== Processing
101137

0 commit comments

Comments
 (0)