
@Configuration
@EnableAsync
public class AsyncConfig {
@Bean("taskExecutor")
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(20); // only 20 run at same time
executor.setMaxPoolSize(20);
executor.setQueueCapacity(10000);
executor.setThreadNamePrefix("task-");
executor.initialize();
return executor;
}
}