public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport implements MethodInterceptor, org.springframework.core.Ordered
MethodInterceptor that processes method invocations
asynchronously, using a given AsyncTaskExecutor.
Typically used with the org.springframework.scheduling.annotation.Async annotation.
In terms of target method signatures, any parameter types are supported.
However, the return type is constrained to either void or
java.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's org.springframework.scheduling.annotation.AsyncResult
or EJB 3.1's javax.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. With void
return type however, such exceptions cannot be transmitted back. In that case an
AsyncUncaughtExceptionHandler 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.
org.springframework.scheduling.annotation.Async,
org.springframework.scheduling.annotation.AsyncAnnotationAdvisor,
org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptorDEFAULT_TASK_EXECUTOR_BEAN_NAME, logger| Constructor and Description |
|---|
AsyncExecutionInterceptor(Executor defaultExecutor)
Create a new instance with a default
AsyncUncaughtExceptionHandler. |
AsyncExecutionInterceptor(Executor defaultExecutor,
AsyncUncaughtExceptionHandler exceptionHandler)
Create a new
AsyncExecutionInterceptor. |
| Modifier and Type | Method and Description |
|---|---|
protected Executor |
getDefaultExecutor(org.springframework.beans.factory.BeanFactory beanFactory)
This implementation searches for a unique
TaskExecutor
bean in the context, or for an Executor bean named "taskExecutor" otherwise. |
protected String |
getExecutorQualifier(Method method)
This implementation is a no-op for compatibility in Spring 3.1.2.
|
int |
getOrder() |
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.
|
determineAsyncExecutor, doSubmit, findQualifiedExecutor, handleError, setBeanFactory, setExceptionHandler, setExecutorpublic AsyncExecutionInterceptor(Executor defaultExecutor)
AsyncUncaughtExceptionHandler.defaultExecutor - the Executor (typically a Spring AsyncTaskExecutor
or ExecutorService) to delegate to;
as of 4.2.6, a local executor for this interceptor will be built otherwisepublic AsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler)
AsyncExecutionInterceptor.defaultExecutor - the Executor (typically a Spring AsyncTaskExecutor
or ExecutorService) to delegate to;
as of 4.2.6, a local executor for this interceptor will be built otherwiseexceptionHandler - the AsyncUncaughtExceptionHandler to usepublic Object invoke(MethodInvocation invocation) throws Throwable
invoke in interface MethodInterceptorinvocation - the method to intercept and make asynchronousFuture if the original method returns Future; null
otherwise.Throwableprotected String getExecutorQualifier(Method method)
getExecutorQualifier in class AsyncExecutionAspectSupportmethod - the method to inspect for executor qualifier metadatanullAsyncExecutionAspectSupport.determineAsyncExecutor(Method)protected Executor getDefaultExecutor(org.springframework.beans.factory.BeanFactory beanFactory)
TaskExecutor
bean in the context, or for an Executor bean named "taskExecutor" otherwise.
If neither of the two is resolvable (e.g. if no BeanFactory was configured at all),
this implementation falls back to a newly created SimpleAsyncTaskExecutor instance
for local use if no default could be found.getDefaultExecutor in class AsyncExecutionAspectSupportbeanFactory - the BeanFactory to use for a default executor lookupnull if none availableAsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR_BEAN_NAMEpublic int getOrder()
getOrder in interface org.springframework.core.Ordered