springboot线程池配置

本文详细介绍了如何在SpringBoot应用中配置线程池,包括在`application.yml`文件中的配置,创建自定义的配置类,以及如何通过注解在Service方法上使用线程池进行任务调度。
摘要由CSDN通过智能技术生成

1. application.yml配置

# 异步线程配置
# 配置核心线程数
async.executor.thread.core_pool_size: 10
# 配置最大线程数
async.executor.thread.max_pool_size: 20
# 配置队列大小
async.executor.thread.queue_capacity: 99999
# 配置线程池中的线程的名称前缀
async.executor.thread.name.prefix: async-service-

2. config配置类

@Configuration
@EnableAsync
public class ExecutorConfig {

    private static final Logger logger = LoggerFactory.getLogger(ExecutorConfig1.class);

    @Value("${async.executor.thread.core_pool_size}")
    private int corePoolSize;
    @Value("${async.executor.thread.max_pool_size}")
    private int maxPoolSize;
    @Value("${async.executor.thread.queue_capacity}")
    private int queueCapacity;
    @Value("${async.executor.thread.name.prefix}")
    private String namePrefix;

    @Bean(name = "asyncServiceExecutor")
    public Executor asyncServiceExecutor() {
        logger.info("======
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值