| | |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; |
| | | |
| | | import java.util.concurrent.Executor; |
| | | |
| | | /** |
| | | * Created by vincent on 11/12/2024 |
| | | */ |
| | | @Configuration |
| | | @EnableAsync |
| | | @EnableScheduling |
| | | public class SchedulerConfig { |
| | | |
| | |
| | | return scheduler; |
| | | } |
| | | |
| | | @Bean(name = "taskExecutor") |
| | | public Executor taskExecutor() { |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | | executor.setCorePoolSize(8); |
| | | executor.setMaxPoolSize(16); |
| | | executor.setQueueCapacity(200); |
| | | executor.setThreadNamePrefix("async-task-"); |
| | | executor.setWaitForTasksToCompleteOnShutdown(true); |
| | | executor.setAwaitTerminationSeconds(30); |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | |
| | | } |
| | | |