类 AsyncExecutionInterceptor
- 所有已实现的接口:
infra.beans.factory.Aware,infra.beans.factory.BeanFactoryAware,infra.core.Ordered,Advice,Interceptor,MethodInterceptor
MethodInterceptor that processes method invocations
asynchronously, using a given AsyncTaskExecutor.
Typically used with the infra.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 infra.scheduling.annotation.AsyncResult
or EJB's jakarta.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.
The AnnotationAsyncExecutionInterceptor subclass is preferred for use
due to its support for executor qualification in conjunction with @Async annotation.
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller, Chris Beams, Stephane Nicoll, Harry Yang
- 另请参阅:
-
infra.scheduling.annotation.Asyncinfra.scheduling.annotation.AsyncAnnotationAdvisorinfra.scheduling.annotation.AnnotationAsyncExecutionInterceptor
-
字段概要
从类继承的字段 infra.aop.interceptor.AsyncExecutionAspectSupport
DEFAULT_TASK_EXECUTOR_BEAN_NAME从接口继承的字段 infra.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器构造器说明AsyncExecutionInterceptor(Executor defaultExecutor) Create a new instance with a defaultAsyncUncaughtExceptionHandler.AsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) Create a newAsyncExecutionInterceptor. -
方法概要
修饰符和类型方法说明protected ExecutorgetDefaultExecutor(infra.beans.factory.BeanFactory beanFactory) This implementation searches for a uniqueTaskExecutorbean in the context, or for anExecutorbean named "taskExecutor" otherwise.protected StringgetExecutorQualifier(Method method) Subclasses may override to provide support for extracting qualifier information, e.g. via an annotation on the given method.intgetOrder()invoke(MethodInvocation invocation) Intercept the given method invocation, submit the actual calling of the method to the correct task executor and return immediately to the caller.从类继承的方法 infra.aop.interceptor.AsyncExecutionAspectSupport
configure, determineAsyncExecutor, doSubmit, findQualifiedExecutor, handleError, setBeanFactory, setExceptionHandler, setExecutor
-
构造器详细资料
-
AsyncExecutionInterceptor
Create a new instance with a defaultAsyncUncaughtExceptionHandler.- 参数:
defaultExecutor- theExecutor(typically a FrameworkAsyncTaskExecutororExecutorService) to delegate to; a local executor for this interceptor will be built otherwise
-
AsyncExecutionInterceptor
public AsyncExecutionInterceptor(@Nullable Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) Create a newAsyncExecutionInterceptor.- 参数:
defaultExecutor- theExecutor(typically a FrameworkAsyncTaskExecutororExecutorService) to delegate to; a local executor for this interceptor will be built otherwiseexceptionHandler- theAsyncUncaughtExceptionHandlerto use
-
-
方法详细资料
-
invoke
Intercept the given method invocation, submit the actual calling of the method to the correct task executor and return immediately to the caller.- 指定者:
invoke在接口中MethodInterceptor- 参数:
invocation- the method to intercept and make asynchronous- 返回:
Futureif the original method returnsFuture;nullotherwise.- 抛出:
Throwable- if the interceptors or the target-object throws an exception.
-
getExecutorQualifier
Subclasses may override to provide support for extracting qualifier information, e.g. via an annotation on the given method.- 指定者:
getExecutorQualifier在类中AsyncExecutionAspectSupport- 参数:
method- the method to inspect for executor qualifier metadata- 返回:
- always
null - 另请参阅:
-
getDefaultExecutor
@Nullable protected Executor getDefaultExecutor(@Nullable infra.beans.factory.BeanFactory beanFactory) This implementation searches for a uniqueTaskExecutorbean in the context, or for anExecutorbean named "taskExecutor" otherwise. If neither of the two is resolvable (e.g. if noBeanFactorywas configured at all), this implementation falls back to a newly createdSimpleAsyncTaskExecutorinstance for local use if no default could be found.- 覆盖:
getDefaultExecutor在类中AsyncExecutionAspectSupport- 参数:
beanFactory- the BeanFactory to use for a default executor lookup- 返回:
- the default executor, or
nullif none available - 另请参阅:
-
getOrder
public int getOrder()- 指定者:
getOrder在接口中infra.core.Ordered
-