|
4 | 4 | Spring MVC has an extensive integration with Servlet asynchronous request
|
5 | 5 | xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-processing[processing]:
|
6 | 6 |
|
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) |
8 | 8 | return values in controller methods provide basic support for a single asynchronous
|
9 | 9 | return value.
|
10 | 10 | * 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
|
96 | 96 |
|
97 | 97 |
|
98 | 98 |
|
| 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 | + |
99 | 135 | [[mvc-ann-async-processing]]
|
100 | 136 | == Processing
|
101 | 137 |
|
|
0 commit comments