接口 AsyncHandlerInterceptor
- 所有超级接口:
HandlerInterceptor
- 所有已知实现类:
ConversionServiceExposingInterceptor
,HandlerInterceptorAdapter
,LocaleChangeInterceptor
,ResourceUrlProviderExposingInterceptor
,ThemeChangeInterceptor
,UserRoleAuthorizationInterceptor
,WebRequestHandlerInterceptorAdapter
public interface AsyncHandlerInterceptor extends HandlerInterceptor
ExtendsHandlerInterceptor
with a callback method invoked after the start of asynchronous request handling.When a handler starts an asynchronous request, the
DispatcherServlet
exits without invokingpostHandle
andafterCompletion
as it normally does for a synchronous request, since the result of request handling (e.g. ModelAndView) is likely not yet ready and will be produced concurrently from another thread. In such scenarios,afterConcurrentHandlingStarted(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
is invoked instead, allowing implementations to perform tasks such as cleaning up thread-bound attributes before releasing the thread to the Servlet container.When asynchronous handling completes, the request is dispatched to the container for further processing. At this stage the
DispatcherServlet
invokespreHandle
,postHandle
, andafterCompletion
. To distinguish between the initial request and the subsequent dispatch after asynchronous handling completes, interceptors can check whether thejavax.servlet.DispatcherType
ofServletRequest
is"REQUEST"
or"ASYNC"
.Note that
HandlerInterceptor
implementations may need to do work when an async request times out or completes with a network error. For such cases the Servlet container does not dispatch and therefore thepostHandle
andafterCompletion
methods will not be invoked. Instead, interceptors can register to track an asynchronous request through theregisterCallbackInterceptor
andregisterDeferredResultInterceptor
methods onWebAsyncManager
. This can be done proactively on every request frompreHandle
regardless of whether async request processing will start.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev
- 另请参阅:
WebAsyncManager
,CallableProcessingInterceptor
,DeferredResultProcessingInterceptor
方法概要
所有方法 实例方法 默认方法 修饰符和类型 方法 说明 default void
afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler)
Called instead ofpostHandle
andafterCompletion
when the handler is being executed concurrently.从接口继承的方法 org.springframework.web.servlet.HandlerInterceptor
afterCompletion, postHandle, preHandle
方法详细资料
afterConcurrentHandlingStarted
default void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
Called instead ofpostHandle
andafterCompletion
when the handler is being executed concurrently.Implementations may use the provided request and response but should avoid modifying them in ways that would conflict with the concurrent execution of the handler. A typical use of this method would be to clean up thread-local variables.
- 参数:
request
- the current requestresponse
- the current responsehandler
- the handler (orHandlerMethod
) that started async execution, for type and/or instance examination- 抛出:
Exception
- in case of errors