I have two instances running for my spring boot project. There I have a scheduled task with defined interval. Now the problem is, both instances are running that scheduled task. I used lock but it just locked when it was working on that task. Once it finishes, another instance starts working on that. Is it possible to run scheduled tasks from one instance only? If one instance completes the task, then no one will work on that in between defined interval?