package com.ruoyi.framework.config; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.concurrent.Executor; import java.util.concurrent.ThreadPoolExecutor; /** * 异步任务配置 * 用于配置 @Async 注解使用的线程池 */ @Configuration public class AsyncConfig implements AsyncConfigurer { @Autowired private ThreadPoolTaskExecutor threadPoolTaskExecutor; @Override public Executor getAsyncExecutor() { return threadPoolTaskExecutor; } @Override public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return (throwable, method, params) -> { System.err.println("异步任务执行异常: " + method.getName() + " 参数: " + params); throwable.printStackTrace(); }; } }