Yes, all @Scheduled
methods share a single thread by default.
It is possible to override this behavior by defining a @Configuration
such as this:
@Configuration
public class SchedulingConfigurerConfiguration implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(100);
taskScheduler.initialize();
taskRegistrar.setTaskScheduler(taskScheduler);
}
}
This example ensures that all @Scheduled
methods share a thread pool of size 100.