I have the following Spring scheduler configuration class:
@Configuration
@EnableScheduling
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SchedulerConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskScheduler());
}
@Bean
public TaskScheduler taskScheduler() {
TaskScheduler taskScheduler= new ConcurrentTaskScheduler();
return taskScheduler;
}
}
and I have an another class
public class Sample
{
@Autowired
TaskScheduler taskScheduler
}
Is the taskScheduler object from "Sample" class different from the object setup at "taskRegistrar.setScheduler(taskScheduler());" class? Is "taskScheduler() call returning different instance than the object injected in the "Sample" class?
If so, how do we ensure there is only one instance of of TaskScheduler in the project? I tried Singleton scope, but still not sure if it ensures same object.