Posts

Showing posts from March, 2021

Spring Boot Scheduler for Distributed System: Using shedlock

Image
  When we want to execute something on a routine/scheduled basis, we need something which can automatically do such an operation if our app is running on the server. To achieve that, we can follow one of many ways. But I prefer Spring scheduler to do my scheduled job for its user-friendly use cases.   So, for spring boot, it is very easy to set up a scheduler method. Let's configure. Please note that, in this writing, I will only mention the vital portion/code snippet for brevity. You will find the whole code linked to GitHub end of this writing. So, what we need for this? So far we don't need anything rather than basic libraries for spring boot app development. Let's configure a Scheduler class: Schedular.java: @Component @Log4j2 @EnableScheduling public class Schedular { @Scheduled(initialDelayString = "${initial.delay}", fixedDelayString = "${fixed.delay}") public void scheduledJob() { log.info("*** my schedular