Skip to content

Add a section for WebAsyncTask in mvc-ann-async.adoc #34885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion framework-docs/modules/ROOT/pages/web/webmvc/mvc-ann-async.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Spring MVC has an extensive integration with Servlet asynchronous request
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-processing[processing]:

* 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`]
* 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)
return values in controller methods provide basic support for a single asynchronous
return value.
* Controllers can xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-http-streaming[stream] multiple values, including
Expand Down Expand Up @@ -96,6 +96,42 @@ xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-configuration-spring-mvc[config



[[mvc-ann-async-webasynctask]]
== `WebAsyncTask`

`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`:

[tabs]
======
Java::
+
[source,java,indent=0,subs="verbatim,quotes"]
----
@GetMapping("/callable")
WebAsyncTask<String> asynchronousRequestProcessingWithCallableWrappedInaWebAsyncTask() {
return new WebAsyncTask<String>(20000L,()->{
Thread.sleep(10000); //simulate long running task
return "asynchronous request completed";
});
}
----

Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
@GetMapping("/callable")
fun asynchronousRequestProcessingWithCallableWrappedInWebAsyncTask(): WebAsyncTask<String> {
return WebAsyncTask(20000L) {
Thread.sleep(10000) // simulate long-running task
"asynchronous request completed"
}
}
----
======



[[mvc-ann-async-processing]]
== Processing

Expand Down