diff --git a/src/main/java/cn/van/business/config/AsyncConfig.java b/src/main/java/cn/van/business/config/AsyncConfig.java index 18f6383..5429179 100644 --- a/src/main/java/cn/van/business/config/AsyncConfig.java +++ b/src/main/java/cn/van/business/config/AsyncConfig.java @@ -1,5 +1,7 @@ package cn.van.business.config; +import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; +import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.annotation.EnableAsync; @@ -21,10 +23,17 @@ public class AsyncConfig implements AsyncConfigurer { @Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - executor.setCorePoolSize(10); - executor.setMaxPoolSize(128); - executor.setQueueCapacity(500); - executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); - executor.initialize(); + executor.setCorePoolSize(10); // 核心线程数 + executor.setMaxPoolSize(128); // 最大线程数 + executor.setQueueCapacity(500); // 队列容量 + executor.setThreadNamePrefix("Async-Executor-"); + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略 + executor.initialize(); // 初始化执行器 + return executor; // 返回执行器 + } + + @Override + public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { + return new SimpleAsyncUncaughtExceptionHandler(); } }