org.springframework.aop.interceptor

## 类 AsyncExecutionAspectSupport

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

- 所有已实现的接口:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware
  直接已知子类:
    AsyncExecutionInterceptor

      public abstract class AsyncExecutionAspectSupport
      extends Object
      implements org.springframework.beans.factory.BeanFactoryAware

  Base class for asynchronous method execution aspects, such as `org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor` or `org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect`.

  Provides support for executor qualification on a method-by-method basis. `AsyncExecutionAspectSupport` objects must be constructed with a default `Executor`, but each individual method may further qualify a specific `Executor` bean to be used when executing it, e.g. through an annotation attribute.

  从以下版本开始:
    3.1.2
  作者:
    Chris Beams, Juergen Hoeller, Stephane Nicoll

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `static String` | `DEFAULT_TASK_EXECUTOR_BEAN_NAME` The default name of the `TaskExecutor` bean to pick up: "taskExecutor".
    `protected Log` | `logger`

  - ### 构造器概要

    构造器
    构造器和说明
    `AsyncExecutionAspectSupport(Executor defaultExecutor)` Create a new instance with a default `AsyncUncaughtExceptionHandler`.
    `AsyncExecutionAspectSupport(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler)` Create a new `AsyncExecutionAspectSupport` with the given exception handler.

  - ### 方法概要

    所有方法 实例方法 抽象方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected org.springframework.core.task.AsyncTaskExecutor` | `determineAsyncExecutor(Method method)` Determine the specific executor to use when executing the given method.
    `protected Object` | `doSubmit(Callable<Object> task, org.springframework.core.task.AsyncTaskExecutor executor, Class<?> returnType)` Delegate for actually executing the given task with the chosen executor.
    `protected Executor` | `findQualifiedExecutor(org.springframework.beans.factory.BeanFactory beanFactory, String qualifier)` Retrieve a target executor for the given qualifier.
    `protected Executor` | `getDefaultExecutor(org.springframework.beans.factory.BeanFactory beanFactory)` Retrieve or build a default executor for this advice instance.
    `protected abstract String` | `getExecutorQualifier(Method method)` Return the qualifier or bean name of the executor to be used when executing the given async method, typically specified in the form of an annotation attribute.
    `protected void` | `handleError(Throwable ex, Method method, Object... params)` Handles a fatal error thrown while asynchronously invoking the specified `Method`.
    `void` | `setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)` Set the `BeanFactory` to be used when looking up executors by qualifier or when relying on the default executor lookup algorithm.
    `void` | `setExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler)` Supply the `AsyncUncaughtExceptionHandler` to use to handle exceptions thrown by invoking asynchronous methods with a `void` return type.
    `void` | `setExecutor(Executor defaultExecutor)` Supply the executor to be used when executing async methods.

    - ### 从类继承的方法 java.lang.Object

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

- - ### 字段详细资料

    - #### DEFAULT_TASK_EXECUTOR_BEAN_NAME

          public static final String DEFAULT_TASK_EXECUTOR_BEAN_NAME

      The default name of the `TaskExecutor` bean to pick up: "taskExecutor".

      Note that the initial lookup happens by type; this is just the fallback in case of multiple executor beans found in the context.

      从以下版本开始:
        4.2.6
      另请参阅:
        常量字段值

    - #### logger

          protected final Log logger

  - ### 构造器详细资料

    - #### AsyncExecutionAspectSupport

          public AsyncExecutionAspectSupport(@Nullable
                                             Executor defaultExecutor)

      Create a new instance with a default `AsyncUncaughtExceptionHandler`.
      参数:
        `defaultExecutor` - the `Executor` (typically a Spring `AsyncTaskExecutor` or `ExecutorService`) to delegate to, unless a more specific executor has been requested via a qualifier on the async method, in which case the executor will be looked up at invocation time against the enclosing bean factory

    - #### AsyncExecutionAspectSupport

          public AsyncExecutionAspectSupport(@Nullable
                                             Executor defaultExecutor,
                                             AsyncUncaughtExceptionHandler exceptionHandler)

      Create a new `AsyncExecutionAspectSupport` with the given exception handler.
      参数:
        `defaultExecutor` - the `Executor` (typically a Spring `AsyncTaskExecutor` or `ExecutorService`) to delegate to, unless a more specific executor has been requested via a qualifier on the async method, in which case the executor will be looked up at invocation time against the enclosing bean factory
        `exceptionHandler` - the `AsyncUncaughtExceptionHandler` to use

  - ### 方法详细资料

    - #### setExecutor

          public void setExecutor(Executor defaultExecutor)

      Supply the executor to be used when executing async methods.
      参数:
        `defaultExecutor` - the `Executor` (typically a Spring `AsyncTaskExecutor` or `ExecutorService`) to delegate to, unless a more specific executor has been requested via a qualifier on the async method, in which case the executor will be looked up at invocation time against the enclosing bean factory
      另请参阅:
        `getExecutorQualifier(Method)`, `setBeanFactory(BeanFactory)`, `getDefaultExecutor(BeanFactory)`

    - #### setExceptionHandler

          public void setExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler)

      Supply the `AsyncUncaughtExceptionHandler` to use to handle exceptions thrown by invoking asynchronous methods with a `void` return type.

    - #### setBeanFactory

          public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)

      Set the `BeanFactory` to be used when looking up executors by qualifier or when relying on the default executor lookup algorithm.
      指定者:
        `setBeanFactory` 在接口中 `org.springframework.beans.factory.BeanFactoryAware`
      另请参阅:
        `findQualifiedExecutor(BeanFactory, String)`, `getDefaultExecutor(BeanFactory)`

    - #### determineAsyncExecutor

          @Nullable
          protected org.springframework.core.task.AsyncTaskExecutor determineAsyncExecutor(Method method)

      Determine the specific executor to use when executing the given method. Should preferably return an `AsyncListenableTaskExecutor` implementation.
      返回:
        the executor to use (or `null`, but just if no default executor is available)

    - #### getExecutorQualifier

          @Nullable
          protected abstract String getExecutorQualifier(Method method)

      Return the qualifier or bean name of the executor to be used when executing the given async method, typically specified in the form of an annotation attribute. Returning an empty string or `null` indicates that no specific executor has been specified and that the default executor should be used.
      参数:
        `method` - the method to inspect for executor qualifier metadata
      返回:
        the qualifier if specified, otherwise empty String or `null`
      另请参阅:
        `determineAsyncExecutor(Method)`, `findQualifiedExecutor(BeanFactory, String)`

    - #### findQualifiedExecutor

          @Nullable
          protected Executor findQualifiedExecutor(@Nullable
                                                              org.springframework.beans.factory.BeanFactory beanFactory,
                                                              String qualifier)

      Retrieve a target executor for the given qualifier.
      参数:
        `qualifier` - the qualifier to resolve
      返回:
        the target executor, or `null` if none available
      从以下版本开始:
        4.2.6
      另请参阅:
        `getExecutorQualifier(Method)`

    - #### getDefaultExecutor

          @Nullable
          protected Executor getDefaultExecutor(@Nullable
                                                           org.springframework.beans.factory.BeanFactory beanFactory)

      Retrieve or build a default executor for this advice instance. An executor returned from here will be cached for further use.

      The default implementation searches for a unique `TaskExecutor` bean in the context, or for an `Executor` bean named "taskExecutor" otherwise. If neither of the two is resolvable, this implementation will return `null`.

      参数:
        `beanFactory` - the BeanFactory to use for a default executor lookup
      返回:
        the default executor, or `null` if none available
      从以下版本开始:
        4.2.6
      另请参阅:
        `findQualifiedExecutor(BeanFactory, String)`, `DEFAULT_TASK_EXECUTOR_BEAN_NAME`

    - #### doSubmit

          @Nullable
          protected Object doSubmit(Callable<Object> task,
                                               org.springframework.core.task.AsyncTaskExecutor executor,
                                               Class<?> returnType)

      Delegate for actually executing the given task with the chosen executor.
      参数:
        `task` - the task to execute
        `executor` - the chosen executor
        `returnType` - the declared return type (potentially a `Future` variant)
      返回:
        the execution result (potentially a corresponding `Future` handle)

    - #### handleError

          protected void handleError(Throwable ex,
                                     Method method,
                                     Object... params)
                              throws Exception

      Handles a fatal error thrown while asynchronously invoking the specified `Method`.

      If the return type of the method is a `Future` object, the original exception can be propagated by just throwing it at the higher level. However, for all other cases, the exception will not be transmitted back to the client. In that later case, the current `AsyncUncaughtExceptionHandler` will be used to manage such exception.

      参数:
        `ex` - the exception to handle
        `method` - the method that was invoked
        `params` - the parameters used to invoke the method
      抛出:
        `Exception`