MethodInterceptor that processes method invocations
asynchronously, using a given org.springframework.core.task.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.
or EJB's jakarta.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.
Note
the AnnotationAsyncExecutionInterceptor subclass is preferred
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.AnnotationAsyncExecutionInterceptor
| Access | Constructor and Description |
|---|---|
| public | AsyncExecutionInterceptor(Executor
the defaultExecutor)Executor (typically a Spring AsyncTaskExecutor
or java.) to delegate to; a local
executor for this interceptor will be built otherwiseCreate a new instance with a default |
| public | AsyncExecutionInterceptor(Executor
the defaultExecutor, AsyncUncaughtExceptionHandler Executor (typically a Spring AsyncTaskExecutor
or java.) to delegate to; a local
executor for this interceptor will be built otherwisethe exceptionHandler)AsyncUncaughtExceptionHandler to useCreate a new |
| Modifier and Type | Method and Description |
|---|---|
| protected Executor | getDefaultExecutor(BeanFactory
the BeanFactory to use for a default executor lookup beanFactory)Overrides org. This implementation searches for a unique |
| protected String | Returns: alwaysnullthe method to inspect for executor qualifier metadata method)Implements abstract org. Get the qualifier for a specific executor to use when executing the given method. |
| public int | |
| public Object | invoke(final MethodInvocation
the method to intercept and make asynchronous invocation)Implements org. Intercept the given method invocation, submit the actual calling of the method to the correct task executor and return immediately to the caller. |
| AsyncExecutionInterceptor | back to summary |
|---|---|
| public AsyncExecutionInterceptor(Executor defaultExecutor) Create a new instance with a default
| |
| AsyncExecutionInterceptor | back to summary |
|---|---|
| public AsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) Create a new
| |
| getDefaultExecutor | back to summary |
|---|---|
| protected Executor getDefaultExecutor(BeanFactory beanFactory) Overrides org. This implementation searches for a unique
| |
| getExecutorQualifier | back to summary |
|---|---|
| protected String getExecutorQualifier(Method method) Implements abstract org. Get the qualifier for a specific executor to use when executing the given method. The default implementation of this method is effectively a no-op. Subclasses may override this method to provide support for extracting qualifier information — for example, via an annotation on the given method.
| |
| getOrder | back to summary |
|---|---|
| public int getOrder() Implements org. Doc from org. 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 Same order values will result in arbitrary sort positions for the affected objects.
| |
| invoke | back to summary |
|---|---|
| public Object invoke(final MethodInvocation invocation) throws Throwable Implements org. Intercept the given method invocation, submit the actual calling of the method to the correct task executor and return immediately to the caller.
| |