Multiple Spring @Scheduled tasks simultaneously

You should use TaskScheduler for your purpose

@Bean
public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
    ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
    threadPoolTaskScheduler.setPoolSize(THREADS_COUNT);
    return threadPoolTaskScheduler;
}

Where THREADS_COUNT – total count of tasks which should be executed in parallel. If I understand you correctly, you have only 2 jobs, so you need 2 threads

Leave a Comment

tech