spring-framework / org.springframework.aop.interceptor / AsyncExecutionAspectSupport

AsyncExecutionAspectSupport

abstract class AsyncExecutionAspectSupport : 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.

Author
Chris Beams

Author
Juergen Hoeller

Author
Stephane Nicoll

Since
3.1.2

Constructors

<init>

AsyncExecutionAspectSupport(defaultExecutor: Executor)

Create a new instance with a default AsyncUncaughtExceptionHandler.

AsyncExecutionAspectSupport(defaultExecutor: Executor, exceptionHandler: AsyncUncaughtExceptionHandler)

Create a new AsyncExecutionAspectSupport with the given exception handler.

Properties

DEFAULT_TASK_EXECUTOR_BEAN_NAME

static val DEFAULT_TASK_EXECUTOR_BEAN_NAME: String

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.

Functions

setBeanFactory

open fun setBeanFactory(beanFactory: BeanFactory): Unit

Set the BeanFactory to be used when looking up executors by qualifier or when relying on the default executor lookup algorithm.

setExceptionHandler

open fun setExceptionHandler(exceptionHandler: AsyncUncaughtExceptionHandler): Unit

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

setExecutor

open fun setExecutor(defaultExecutor: Executor): Unit

Supply the executor to be used when executing async methods.

Inheritors

AsyncExecutionInterceptor

open class AsyncExecutionInterceptor : AsyncExecutionAspectSupport, MethodInterceptor, Ordered

AOP Alliance 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.springframework.scheduling.annotation.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.