You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce @DistributedLock annotation that can be used together with @Scheduled annotation to execute scheduled task only once in a given time window across all instances of the same Microservice.
Problem
Currently when using @Scheduled annotation for Microservices that have more than one instance, Scheduled Task will be executed multiple times across different Microservices instances at the same time.
In some cases you want to execute Scheduled Task only once across all instances of the same Microservice.
Current Solutions
Solutions exists, however they are not as easy as using single @DistributedLock annotation. Some examples include:
Introduce custom annotation that will use RDBMS as a synchronization point to hold locks across multiple Microservices
Use a Cloud Pattern - for example Create an HTTP function that is triggered by Cloud Scheduler
Use Lambda
Use Event Queue with Single Consumer
Spring Integration Distributed Lock
...
Proposed Solution
Introduce easy to use annotation @DistributedLock that would use some form of abstraction for distributed locks. By default it could use RDBMS.
It is important to implement min lock time functionality to prevent execution of the scheduled task multiple times under cases when one instance starts with a slight delay.
Example:
task should be executed every 10 seconds
task execution time is 2 seconds
Instance 2 starts with a 7 seconds delay compared to Instance 1
Because of the delay in startup, task schedule looks like below:
Problem: Without min lock time set to 10 seconds, when Instance 1 starts the task at 09:00:00, and when task is finished after 2 seconds at 09:00:02, the Instance 2 would execute the task at 09:00:07.
Solution: Introduce min lock time to prevent the other instance with delayed startup time to execute scheduled task more often then specified by a schedule.
The text was updated successfully, but these errors were encountered:
The ShedLock library already provides such a feature with many implementations. If you need more control for distributed jobs/scheduling look at libraries like JobRunr or good ol' Quartz.
Would it be possible to consider having ShedLock as an official Spring Project so that it would be covered by Spring Enterprise Support for LTS as well?
Overview
Introduce
@DistributedLock
annotation that can be used together with@Scheduled
annotation to execute scheduled task only once in a given time window across all instances of the same Microservice.Problem
Currently when using
@Scheduled
annotation for Microservices that have more than one instance, Scheduled Task will be executed multiple times across different Microservices instances at the same time.In some cases you want to execute Scheduled Task only once across all instances of the same Microservice.
Current Solutions
Solutions exists, however they are not as easy as using single
@DistributedLock
annotation. Some examples include:Proposed Solution
Introduce easy to use annotation
@DistributedLock
that would use some form of abstraction for distributed locks. By default it could use RDBMS.Usage would look like below:
Details
Min Lock Time
It is important to implement min lock time functionality to prevent execution of the scheduled task multiple times under cases when one instance starts with a slight delay.
Example:
Problem: Without min lock time set to 10 seconds, when Instance 1 starts the task at 09:00:00, and when task is finished after 2 seconds at 09:00:02, the Instance 2 would execute the task at 09:00:07.
Solution: Introduce min lock time to prevent the other instance with delayed startup time to execute scheduled task more often then specified by a schedule.
The text was updated successfully, but these errors were encountered: