1package com.example.config;
2
3import org.springframework.context.annotation.Configuration;
4import org.springframework.core.task.AsyncTaskExecutor;
5import org.springframework.scheduling.annotation.EnableAsync;
6import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
7
8import java.util.concurrent.Executor;
9
10@Configuration
11@EnableAsync // @Asyncの有効化
12public class AsyncConfig {
13 @Bean
14 public AsyncTaskExecutor taskExecutor() { // デフォルトだと"taskExecutor"という名前のBeanが利用される
15 ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
16 executor.setCorePoolSize(10);
17 executor.setMaxPoolSize(10);
18 executor.setQueueCapacity(10);
19 return executor;
20 }
21}
22