简介
先看下代码吧
public interface AsyncConfigurer {
/**
* The {@link Executor} instance to be used when processing async
* method invocations.
*/
@Nullable
default Executor getAsyncExecutor() {
return null;
}
/**
* The {@link AsyncUncaughtExceptionHandler} instance to be used
* when an exception is thrown during an asynchronous method execution
* with {@code void} return type.
*/
@Nullable
default AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return null;
}
}
顾名思义,这个接口作用只有两个
- 配置异步线程池;
- 配置AsyncUncaughtExceptionHandler。
第一个作用在此就不做解释了,第二个作用也简单,如果你的方法没有返回类型又想处理未捕获异常异常的话,用它就是了。
源码如下:
@FunctionalInterface
public interface AsyncUncaughtExceptionHandler {
/**
* Handle the given uncaught exception thrown from an asynchronous method.
* @param ex the exception thrown from the asynchronous method
* @param method the asynchronous method
* @param params the parameters used to invoked the method
*/
void handleUncaughtException(Throwable ex, Method method, Object... params);
}
异常、方法以及参数列表都可以直接获取到。