线程池配置

@Configuration
@EnableAsync
public class ExecutorConfig {
    private static final int poolSizeMin = 30;

    @Bean
    public Executor executor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        String poolSize = "60";
        int poolSizeNum = Integer.parseInt(poolSize);
        if (poolSizeNum < poolSizeMin) {
            poolSizeNum = poolSizeMin;
        }
        executor.setThreadNamePrefix("dataTo-");
        executor.setMaxPoolSize(poolSizeNum);
        executor.setCorePoolSize(poolSizeMin);
        executor.setQueueCapacity(10);
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}

  

posted @ 2023-09-20 21:03  想去大上海  阅读(12)  评论(0)    收藏  举报