1. 程式人生 > >多執行緒配置

多執行緒配置

@Configuration
@EnableAsync
public class AsyncTaskConfig implements AsyncConfigurer {
    @Override
    @Bean
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor threadPoolTaskExecutor=new ThreadPoolTaskExecutor();
        //設定執行緒數
        threadPoolTaskExecutor.setCorePoolSize(10);
//最大執行緒數 threadPoolTaskExecutor.setMaxPoolSize(50); //保持活躍的秒數 threadPoolTaskExecutor.setKeepAliveSeconds(5); //等待佇列容量,執行緒數不夠會等待 threadPoolTaskExecutor.setQueueCapacity(100); //初始化 threadPoolTaskExecutor.initialize(); return threadPoolTaskExecutor;
} @Override @Bean public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return null; } }