类 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.AnnotationAsyncExecutionInterceptorororg.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect.Provides support for executor qualification on a method-by-method basis.
AsyncExecutionAspectSupportobjects must be constructed with a defaultExecutor, but each individual method may further qualify a specificExecutorbean to be used when executing it, e.g. through an annotation attribute.- 从以下版本开始:
- 3.1.2
- 作者:
- Chris Beams, Juergen Hoeller, Stephane Nicoll
字段概要
字段 修饰符和类型 字段 说明 static StringDEFAULT_TASK_EXECUTOR_BEAN_NAMEThe default name of theTaskExecutorbean to pick up: "taskExecutor".protected Loglogger
构造器概要
构造器 构造器 说明 AsyncExecutionAspectSupport(Executor defaultExecutor)Create a new instance with a defaultAsyncUncaughtExceptionHandler.AsyncExecutionAspectSupport(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler)Create a newAsyncExecutionAspectSupportwith the given exception handler.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 voidconfigure(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 AsyncTaskExecutordetermineAsyncExecutor(Method method)Determine the specific executor to use when executing the given method.protected ObjectdoSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType)Delegate for actually executing the given task with the chosen executor.protected ExecutorfindQualifiedExecutor(BeanFactory beanFactory, String qualifier)Retrieve a target executor for the given qualifier.protected ExecutorgetDefaultExecutor(BeanFactory beanFactory)Retrieve or build a default executor for this advice instance.protected abstract StringgetExecutorQualifier(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 voidhandleError(Throwable ex, Method method, Object... params)Handles a fatal error thrown while asynchronously invoking the specifiedMethod.voidsetBeanFactory(BeanFactory beanFactory)Set theBeanFactoryto be used when looking up executors by qualifier or when relying on the default executor lookup algorithm.voidsetExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler)Supply theAsyncUncaughtExceptionHandlerto use to handle exceptions thrown by invoking asynchronous methods with avoidreturn type.voidsetExecutor(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 theTaskExecutorbean 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 SpringAsyncTaskExecutororExecutorService) 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 newAsyncExecutionAspectSupportwith the given exception handler.- 参数:
defaultExecutor- theExecutor(typically a SpringAsyncTaskExecutororExecutorService) 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- theAsyncUncaughtExceptionHandlerto 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 SpringAsyncTaskExecutororExecutorService) 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 theAsyncUncaughtExceptionHandlerto use to handle exceptions thrown by invoking asynchronous methods with avoidreturn type.
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
Set theBeanFactoryto 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 anAsyncListenableTaskExecutorimplementation.- 返回:
- 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 ornullindicates 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
nullif 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
TaskExecutorbean in the context, or for anExecutorbean 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
nullif 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
Futureobject, 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 currentAsyncUncaughtExceptionHandlerwill be used to manage such exception.- 参数:
ex- the exception to handlemethod- the method that was invokedparams- the parameters used to invoke the method- 抛出:
Exception