类 AsyncExecutionInterceptor
- java.lang.Object
- org.springframework.aop.interceptor.AsyncExecutionAspectSupport
- org.springframework.aop.interceptor.AsyncExecutionInterceptor
- 所有已实现的接口:
Advice
,Interceptor
,MethodInterceptor
,Aware
,BeanFactoryAware
,Ordered
public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport implements MethodInterceptor, Ordered
AOP AllianceMethodInterceptor
that processes method invocations asynchronously, using a givenAsyncTaskExecutor
. Typically used with theAsync
annotation.In terms of target method signatures, any parameter types are supported. However, the return type is constrained to either
void
orjava.util.concurrent.Future
. In the latter case, the Future handle returned from the proxy will be an actual asynchronous Future that can be used to track the result of the asynchronous method execution. However, since the target method needs to implement the same signature, it will have to return a temporary Future handle that just passes the return value through (like Spring'sAsyncResult
or EJB 3.1'sjavax.ejb.AsyncResult
).When the return type is
java.util.concurrent.Future
, any exception thrown during the execution can be accessed and managed by the caller. Withvoid
return type however, such exceptions cannot be transmitted back. In that case anAsyncUncaughtExceptionHandler
can be registered to process such exceptions.As of Spring 3.1.2 the
AnnotationAsyncExecutionInterceptor
subclass is preferred for use due to its support for executor qualification in conjunction with Spring's@Async
annotation.- 从以下版本开始:
- 3.0
- 作者:
- Juergen Hoeller, Chris Beams, Stephane Nicoll
- 另请参阅:
Async
,AsyncAnnotationAdvisor
,AnnotationAsyncExecutionInterceptor
字段概要
从类继承的字段 org.springframework.aop.interceptor.AsyncExecutionAspectSupport
DEFAULT_TASK_EXECUTOR_BEAN_NAME, logger
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 AsyncExecutionInterceptor(Executor defaultExecutor)
Create a new instance with a defaultAsyncUncaughtExceptionHandler
.AsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler)
Create a newAsyncExecutionInterceptor
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Executor
getDefaultExecutor(BeanFactory beanFactory)
This implementation searches for a uniqueTaskExecutor
bean in the context, or for anExecutor
bean named "taskExecutor" otherwise.protected String
getExecutorQualifier(Method method)
This implementation is a no-op for compatibility in Spring 3.1.2.int
getOrder()
Get the order value of this object.Object
invoke(MethodInvocation invocation)
Intercept the given method invocation, submit the actual calling of the method to the correct task executor and return immediately to the caller.从类继承的方法 org.springframework.aop.interceptor.AsyncExecutionAspectSupport
determineAsyncExecutor, doSubmit, findQualifiedExecutor, handleError, setBeanFactory, setExceptionHandler, setExecutor
构造器详细资料
AsyncExecutionInterceptor
public AsyncExecutionInterceptor(Executor defaultExecutor)
Create a new instance with a defaultAsyncUncaughtExceptionHandler
.- 参数:
defaultExecutor
- theExecutor
(typically a SpringAsyncTaskExecutor
orExecutorService
) to delegate to; as of 4.2.6, a local executor for this interceptor will be built otherwise
AsyncExecutionInterceptor
public AsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler)
Create a newAsyncExecutionInterceptor
.- 参数:
defaultExecutor
- theExecutor
(typically a SpringAsyncTaskExecutor
orExecutorService
) to delegate to; as of 4.2.6, a local executor for this interceptor will be built otherwiseexceptionHandler
- theAsyncUncaughtExceptionHandler
to use
方法详细资料
invoke
public Object invoke(MethodInvocation invocation) throws Throwable
Intercept the given method invocation, submit the actual calling of the method to the correct task executor and return immediately to the caller.- 指定者:
invoke
在接口中MethodInterceptor
- 参数:
invocation
- the method to intercept and make asynchronous- 返回:
Future
if the original method returnsFuture
;null
otherwise.- 抛出:
Throwable
- if the interceptors or the target object throws an exception
getExecutorQualifier
protected String getExecutorQualifier(Method method)
This implementation is a no-op for compatibility in Spring 3.1.2. Subclasses may override to provide support for extracting qualifier information, e.g. via an annotation on the given method.- 指定者:
getExecutorQualifier
在类中AsyncExecutionAspectSupport
- 参数:
method
- the method to inspect for executor qualifier metadata- 返回:
- always
null
- 从以下版本开始:
- 3.1.2
- 另请参阅:
AsyncExecutionAspectSupport.determineAsyncExecutor(Method)
getDefaultExecutor
protected Executor getDefaultExecutor(BeanFactory beanFactory)
This implementation searches for a uniqueTaskExecutor
bean in the context, or for anExecutor
bean named "taskExecutor" otherwise. If neither of the two is resolvable (e.g. if noBeanFactory
was configured at all), this implementation falls back to a newly createdSimpleAsyncTaskExecutor
instance for local use if no default could be found.- 覆盖:
getDefaultExecutor
在类中AsyncExecutionAspectSupport
- 参数:
beanFactory
- the BeanFactory to use for a default executor lookup- 返回:
- the default executor, or
null
if none available - 另请参阅:
AsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR_BEAN_NAME
getOrder
public int getOrder()
从接口复制的说明:Ordered
Get the order value of this object.Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet
load-on-startup
values).Same order values will result in arbitrary sort positions for the affected objects.
- 指定者:
getOrder
在接口中Ordered
- 返回:
- the order value
- 另请参阅:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE