Class AnnotationAsyncExecutionInterceptor

java.lang.Object
org.springframework.aop.interceptor.AsyncExecutionAspectSupport
org.springframework.aop.interceptor.AsyncExecutionInterceptor
org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.core.Ordered

public class AnnotationAsyncExecutionInterceptor extends org.springframework.aop.interceptor.AsyncExecutionInterceptor
Specialization of AsyncExecutionInterceptor that delegates method execution to an Executor based on the Async annotation.

Specifically designed to support use of the Async.value() executor qualifier mechanism.

Supports detecting qualifier metadata via @Async at the method or declaring class level. See getExecutorQualifier(Method) for details.

Since:
3.1.2
Author:
Chris Beams, Stephane Nicoll
See Also:
  • Field Summary

    Fields inherited from class org.springframework.aop.interceptor.AsyncExecutionAspectSupport

    DEFAULT_TASK_EXECUTOR_BEAN_NAME, logger

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new AnnotationAsyncExecutionInterceptor with the given executor and a simple AsyncUncaughtExceptionHandler.
    AnnotationAsyncExecutionInterceptor(Executor defaultExecutor, org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler exceptionHandler)
    Create a new AnnotationAsyncExecutionInterceptor with the given executor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Return the qualifier or bean name of the executor to be used when executing the given method, specified via Async.value() at the method or declaring class level.

    Methods inherited from class org.springframework.aop.interceptor.AsyncExecutionInterceptor

    getDefaultExecutor, getOrder, invoke

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

    configure, determineAsyncExecutor, doSubmit, findQualifiedExecutor, handleError, setBeanFactory, setExceptionHandler, setExecutor

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AnnotationAsyncExecutionInterceptor

      public AnnotationAsyncExecutionInterceptor(@Nullable Executor defaultExecutor)
      Create a new AnnotationAsyncExecutionInterceptor with the given executor and a simple AsyncUncaughtExceptionHandler.
      Parameters:
      defaultExecutor - the executor to be used by default if no more specific executor has been qualified at the method level using Async.value(); a local executor for this interceptor will be built otherwise
    • AnnotationAsyncExecutionInterceptor

      public AnnotationAsyncExecutionInterceptor(@Nullable Executor defaultExecutor, org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler exceptionHandler)
      Create a new AnnotationAsyncExecutionInterceptor with the given executor.
      Parameters:
      defaultExecutor - the executor to be used by default if no more specific executor has been qualified at the method level using Async.value(); a local executor for this interceptor will be built otherwise
      exceptionHandler - the AsyncUncaughtExceptionHandler to use to handle exceptions thrown by asynchronous method executions with void return type
  • Method Details

    • getExecutorQualifier

      @Nullable protected String getExecutorQualifier(Method method)
      Return the qualifier or bean name of the executor to be used when executing the given method, specified via Async.value() at the method or declaring class level. If @Async is specified at both the method and class level, the method's value takes precedence (even if empty string, indicating that the default executor should be used preferentially).
      Overrides:
      getExecutorQualifier in class org.springframework.aop.interceptor.AsyncExecutionInterceptor
      Parameters:
      method - the method to inspect for executor qualifier metadata
      Returns:
      the qualifier if specified, otherwise an empty string indicating that the default executor should be used
      See Also:
      • AsyncExecutionAspectSupport.determineAsyncExecutor(Method)