Class AsyncExecutionInterceptor

  • All Implemented Interfaces:
    Advice, Interceptor, MethodInterceptor, Aware, BeanFactoryAware, Ordered
    Direct Known Subclasses:

    public class AsyncExecutionInterceptor
    extends AsyncExecutionAspectSupport
    implements MethodInterceptor, Ordered
    AOP Alliance MethodInterceptor that processes method invocations asynchronously, using a given AsyncTaskExecutor. Typically used with the 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 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.

    Juergen Hoeller, Chris Beams, Stephane Nicoll
    See Also:
    Async, AsyncAnnotationAdvisor, AnnotationAsyncExecutionInterceptor
    • Constructor Detail

      • AsyncExecutionInterceptor

        public AsyncExecutionInterceptor(@Nullable
                                         java.util.concurrent.Executor defaultExecutor)
        Create a new instance with a default 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 otherwise
      • AsyncExecutionInterceptor

        public AsyncExecutionInterceptor(@Nullable
                                         java.util.concurrent.Executor defaultExecutor,
                                         AsyncUncaughtExceptionHandler exceptionHandler)
        Create a new 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 otherwise
        exceptionHandler - the AsyncUncaughtExceptionHandler to use
    • Method Detail

      • invoke

        public java.lang.Object invoke(MethodInvocation invocation)
                                          throws java.lang.Throwable
        Intercept the given method invocation, submit the actual calling of the method to the correct task executor and return immediately to the caller.
        Specified by:
        invoke in interface MethodInterceptor
        invocation - the method to intercept and make asynchronous
        Future if the original method returns Future; null otherwise.
        java.lang.Throwable - if the interceptors or the target object throws an exception
      • getOrder

        public int getOrder()
        Description copied from interface: 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.

        Specified by:
        getOrder in interface Ordered
        the order value
        See Also: