I am new for scheduler in spring. I read so many articles on @scheduled , ScheduledExecutorService & TimerTask .
So as per my knowledge @scheduled and ScheduledExecutorService are most of same functionality but if your code is in spring so its better to user @Scheduled annotation in your code.
So my question is Suppose I want to run some task after 15 minutes my program start that means initial delay is 15 min and that task should be run every after 5 minutes means fixedRate is 5 minuter. So by using cron expression how can I achieve it?
Read following links :
- https://dzone.com/articles/schedulers-in-java-and-spring
- https://crontab.guru/#15____
- https://www.baeldung.com/spring-scheduled-tasks
I can achieve the same using following code but I want to write this code with cron expression.
Code :
@Configuration
@EnableScheduling
public class ScheduledConfiguration {
@Scheduled(fixedDelay = 5000, initialDelay = 1000)
public void scheduleFixedRateWithInitialDelayTask() {
long now = System.currentTimeMillis() / 1000;
System.out.println("Fixed rate task with one second initial delay - " + now);
}
}