The exact same instance is used by both your application and the scheduling service. There is no synchronization so the scheduling service may run that method while your application invokes it.
Pretty much the same way as you would have injected TaskService
in something that can be accessed by multiple threads at the same time and those threads call that method concurrently.
There's no black magic behind @Scheduled
: it invokes your method the same way as you would manually. If that method is not thread-safe you need to fallback on regular synchronization mechanism in Java (for instance by adding the synchronized
keyword to your method declaration).