package com.ruoyi.sim.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 非核心业务的线程池。
 */
@Configuration
@EnableAsync
public class AsyncCommThreadPoolConfig {

    @Bean(name = "tp-comm")
    public ThreadPoolTaskExecutor executor() {
        ThreadPoolTaskExecutor e = new ThreadPoolTaskExecutor();
        e.setCorePoolSize(10);
        e.setMaxPoolSize(100);
        e.setQueueCapacity(50);
        e.setKeepAliveSeconds(200);
        e.setThreadNamePrefix("tp-comm-");
        e.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        e.initialize();
        return e;
    }
}
