You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
to the current <interfacename>DispatcherType</interfacename>, which
2450
+
can be used to distinguish if a <interfacename>Servlet</interfacename> or
2451
+
a <interfacename>Filter</interfacename> is processing on
2452
+
the initial request processing thread and when it is processing in
2453
+
an async dispatch.</para>
2454
+
</listitem>
2455
+
</itemizedlist>
2456
+
2457
+
<para>With the above in mind, the following is the sequence
2458
+
of events for async request processing with a <interfacename>Callable</interfacename>:
2459
+
(1) Controller returns a
2460
+
<interfacename>Callable</interfacename>, (2) Spring MVC starts async processing
2461
+
and submits the <interfacename>Callable</interfacename>
2462
+
to a <interfacename>TaskExecutor</interfacename>
2463
+
for processing in a separate thread, (3) the <classname>DispatcherServlet</classname>
2464
+
and all Filter's exit the request processing thread but the response
2465
+
remains open, (4) the <interfacename>Callable</interfacename> produces a result
2466
+
and Spring MVC dispatches the request back to the Servlet container,
2467
+
(5) the <classname>DispatcherServlet</classname> is invoked again and processing
2468
+
resumes with the asynchronously produced result from the
2469
+
<interfacename>Callable</interfacename>. The exact sequencing of (2),
2470
+
(3), and (4) may vary depending on the speed of execution of the
2471
+
concurrent threads.
2472
+
</para>
2473
+
2474
+
<para>The sequence of events for async request processing with a
2475
+
<classname>DeferredResult</classname> is the same in principal except
2476
+
it's up to the application to produce the asynchronous result from some thread:
2477
+
(1) Controller returns a <classname>DeferredResult</classname> and saves it
2478
+
in some in-memory queue or list where it can be accessed,
2479
+
(2) Spring MVC starts async processing, (3) the <classname>DispatcherServlet</classname>
2480
+
and all configured Filter's exit the request processing thread but the response
2481
+
remains open, (4) the application sets the <classname>DeferredResult</classname>
2482
+
from some thread and Spring MVC dispatches the request back to the Servlet container,
2483
+
(5) the <classname>DispatcherServlet</classname> is invoked again and processing
2484
+
resumes with the asynchronously produced result.
2485
+
</para>
2486
+
2487
+
<para>Explaining the motivation for async request processing, when or why to use it
2488
+
is beyond the scope of this document. For further information you may wish to read
2489
+
<linkxl:href="http://http://blog.springsource.org/2012/05/06/spring-mvc-3-2-preview-introducing-servlet-3-async-support/"> this blog post series</link>.
2490
+
</para>
2491
+
2492
+
<sectionxml:id="mvc-ann-async-exceptions">
2493
+
<title>Async Request Processing and Exception Handling</title>
2494
+
2495
+
<para>What happens if a <interfacename>Callable</interfacename> returned
2496
+
from a controller method raises an Exception while being executed?
2497
+
The effect is similar to what happens when any controller method raises
2498
+
an exception. It is handled by a matching
2499
+
<interfacename>@ExceptionHandler</interfacename> method in the same
0 commit comments