ThreadPool的使用

//初始化线程池 
@Configuration
public class ThreadPoolConfig {

    @Bean
    public ThreadPoolTaskExecutor executor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setMaxPoolSize(2);//线程池最多有2个线程
        executor.setCorePoolSize(1);//核心线程数为1
        executor.setThreadNamePrefix("*_*");//线程名称前缀
        executor.setQueueCapacity(100);//线程池等候队列
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());//拒绝策略
        executor.initialize();//初始化
        return executor;
    }
}