10 天以前 f818fa5eca223270f0656e0455c338ec1f2fac88
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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();
        };
    }
}