Application scenarios
When scheduled tasks are used to upload data in batches, several scheduled tasks need to be run at the same time.
Have a problem
Due to bugs, Scheduled tasks are executed in a single thread by default when multiple Scheduled tasks are executed at the same time. That is, when a task is too slow, the subsequent tasks are not executed at the time I want them to be executed.
The solution
@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(50);
return taskScheduler;
}
Copy the code
All you need to do is add the code above and you can change to multi-threaded execution.