javaspringspring-bootshedlock

Spring Shedlock timing issue


We are using Spring Shedlock library to run one instance of task at a time in clustered enviroment. But looks like lock is held until specific time (configured by lockAtMostFor attribute If we dont configure it takes default value from spring config) not until task is finished.

Lets say if I configured lockAtMostFor=15 mins no parellel task runs on any of node for 15 mins, but after 15 mins if any of node gets chance to run(or manually trigger) task its able to start it even if previous task is not finished its processing.

1.Is Shedlock is time based ?

2.Documentation(https://github.com/lukas-krecan/ShedLock) says lock is only released only when task is finished and lockAtMostFor attribute is only used in case node terminition event , but its not working like that even if task is not finished other nodes are able to run task , other nodes are blocked from running task only if time is not elapsed (lockAtMostFor attribute)


Solution

  • Quoting from the documentation:

    You have to set lockAtMostFor to a value that is much longer than normal execution time. If the task takes longer than lockAtMostFor the resulting behavior may be unpredictable (more than one process will effectively hold the lock).