org.springframework.aop.interceptor

## Class AsyncExecutionInterceptor

- java.lang.Object
- - org.springframework.aop.interceptor.AsyncExecutionAspectSupport
  - - org.springframework.aop.interceptor.AsyncExecutionInterceptor

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

      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`).

  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.

  Since:
    3.0
  Author:
    Juergen Hoeller, Chris Beams
  See Also:
    `Async`, `AsyncAnnotationAdvisor`, `AnnotationAsyncExecutionInterceptor`

- - ### Field Summary

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AsyncExecutionInterceptor(Executor executor)` Create a new `AsyncExecutionInterceptor`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected String` | `getExecutorQualifier(Method method)` This implementation is a no-op for compatibility in Spring 3.1.2.
    `int` | `getOrder()` Return the order value of this object, with a higher value meaning greater in terms of sorting.
    `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.

    - ### Methods inherited from class org.springframework.aop.interceptor.AsyncExecutionAspectSupport

      `determineAsyncExecutor, setBeanFactory, setExecutor`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AsyncExecutionInterceptor

          public AsyncExecutionInterceptor(Executor executor)

      Create a new `AsyncExecutionInterceptor`.
      Parameters:
        `executor` - the `Executor` (typically a Spring `AsyncTaskExecutor` or `ExecutorService`) to delegate to.

  - ### Method Detail

    - #### 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.
      Specified by:
        `invoke` in interface `MethodInterceptor`
      Parameters:
        `invocation` - the method to intercept and make asynchronous
      Returns:
        `Future` if the original method returns `Future`; `null` otherwise.
      Throws:
        `Throwable`

    - #### 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.
      Specified by:
        `getExecutorQualifier` in class `AsyncExecutionAspectSupport`
      Parameters:
        `method` - the method to inspect for executor qualifier metadata
      Returns:
        always `null`
      Since:
        3.1.2
      See Also:
        `AsyncExecutionAspectSupport.determineAsyncExecutor(Method)`

    - #### getOrder

          public int getOrder()

      Description copied from interface: `Ordered`
      Return the order value of this object, with a higher value meaning greater in terms of sorting.

      Normally starting with 0, with `Integer.MAX_VALUE` indicating the greatest value. Same order values will result in arbitrary positions for the affected objects.

      Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).

      Specified by:
        `getOrder` in interface `Ordered`
      Returns:
        the order value