类 AsyncExecutionAspectSupport
- java.lang.Object
- org.springframework.aop.interceptor.AsyncExecutionAspectSupport
- 所有已实现的接口:
Aware
,BeanFactoryAware
- 直接已知子类:
AsyncExecutionInterceptor
public abstract class AsyncExecutionAspectSupport extends Object implements BeanFactoryAware
Base class for asynchronous method execution aspects, such asorg.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor
ororg.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect
.Provides support for executor qualification on a method-by-method basis.
AsyncExecutionAspectSupport
objects must be constructed with a defaultExecutor
, but each individual method may further qualify a specificExecutor
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 theTaskExecutor
bean to pick up: "taskExecutor".protected Log
logger
构造器概要
构造器 构造器 说明 AsyncExecutionAspectSupport(Executor defaultExecutor)
Create a new instance with a defaultAsyncUncaughtExceptionHandler
.AsyncExecutionAspectSupport(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler)
Create a newAsyncExecutionAspectSupport
with the given exception handler.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 void
configure(Supplier<Executor> defaultExecutor, Supplier<AsyncUncaughtExceptionHandler> exceptionHandler)
Configure this aspect with the given executor and exception handler suppliers, applying the corresponding default if a supplier is not resolvable.protected AsyncTaskExecutor
determineAsyncExecutor(Method method)
Determine the specific executor to use when executing the given method.protected Object
doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType)
Delegate for actually executing the given task with the chosen executor.protected Executor
findQualifiedExecutor(BeanFactory beanFactory, String qualifier)
Retrieve a target executor for the given qualifier.protected Executor
getDefaultExecutor(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 specifiedMethod
.void
setBeanFactory(BeanFactory beanFactory)
Set theBeanFactory
to be used when looking up executors by qualifier or when relying on the default executor lookup algorithm.void
setExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler)
Supply theAsyncUncaughtExceptionHandler
to use to handle exceptions thrown by invoking asynchronous methods with avoid
return type.void
setExecutor(Executor defaultExecutor)
Supply the executor to be used when executing async methods.
字段详细资料
DEFAULT_TASK_EXECUTOR_BEAN_NAME
public static final String DEFAULT_TASK_EXECUTOR_BEAN_NAME
The default name of theTaskExecutor
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
- 另请参阅:
- 常量字段值
构造器详细资料
AsyncExecutionAspectSupport
public AsyncExecutionAspectSupport(@Nullable Executor defaultExecutor)
Create a new instance with a defaultAsyncUncaughtExceptionHandler
.- 参数:
defaultExecutor
- theExecutor
(typically a SpringAsyncTaskExecutor
orExecutorService
) 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 newAsyncExecutionAspectSupport
with the given exception handler.- 参数:
defaultExecutor
- theExecutor
(typically a SpringAsyncTaskExecutor
orExecutorService
) 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 factoryexceptionHandler
- theAsyncUncaughtExceptionHandler
to use
方法详细资料
configure
public void configure(@Nullable Supplier<Executor> defaultExecutor, @Nullable Supplier<AsyncUncaughtExceptionHandler> exceptionHandler)
Configure this aspect with the given executor and exception handler suppliers, applying the corresponding default if a supplier is not resolvable.- 从以下版本开始:
- 5.1
setExecutor
public void setExecutor(Executor defaultExecutor)
Supply the executor to be used when executing async methods.- 参数:
defaultExecutor
- theExecutor
(typically a SpringAsyncTaskExecutor
orExecutorService
) 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 theAsyncUncaughtExceptionHandler
to use to handle exceptions thrown by invoking asynchronous methods with avoid
return type.
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
Set theBeanFactory
to be used when looking up executors by qualifier or when relying on the default executor lookup algorithm.- 指定者:
setBeanFactory
在接口中BeanFactoryAware
- 参数:
beanFactory
- owning BeanFactory (nevernull
). The bean can immediately call methods on the factory.- 另请参阅:
findQualifiedExecutor(BeanFactory, String)
,getDefaultExecutor(BeanFactory)
determineAsyncExecutor
@Nullable protected AsyncTaskExecutor determineAsyncExecutor(Method method)
Determine the specific executor to use when executing the given method. Should preferably return anAsyncListenableTaskExecutor
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 ornull
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 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 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 anExecutor
bean named "taskExecutor" otherwise. If neither of the two is resolvable, this implementation will returnnull
.- 参数:
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, AsyncTaskExecutor executor, Class<?> returnType)
Delegate for actually executing the given task with the chosen executor.
handleError
protected void handleError(Throwable ex, Method method, Object... params) throws Exception
Handles a fatal error thrown while asynchronously invoking the specifiedMethod
.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 currentAsyncUncaughtExceptionHandler
will be used to manage such exception.- 参数:
ex
- the exception to handlemethod
- the method that was invokedparams
- the parameters used to invoke the method- 抛出:
Exception