How to give minute in fixedDelay & initialDelay in @scheduled spring boot?

坚强是说给别人听的谎言 提交于 2020-06-16 17:33:16

问题


I am new for scheduler in spring. I read so many articles on @schedule but in every example they gave time in seconds and milliseconds.

Problem Statement : As per my requirement, after my program start my scheduler will start after 15 minutes (initial Delay ) and then it executes the task every after 5 minutes (FixedRate) . To achieve this how can I give time in minutes is their any best way to achieve this problem ?

Code :

@Configuration
@EnableScheduling
public class ScheduledConfiguration {
    @Scheduled(fixedDelay = 300000, initialDelay = 900000)
    public void scheduleFixedRateWithInitialDelayTask() {

        long now = System.currentTimeMillis() / 1000;
        System.out.println("Fixed rate task with one second initial delay - " + now);
    }
}

By using above program i will achive but I want to avoid 300000 / 900000 milliseconds . Other way

@Scheduled(fixedDelay = 5 * 60 * 1000, initialDelay = 15 * 60 * 1000)

来源:https://stackoverflow.com/questions/61749805/how-to-give-minute-in-fixeddelay-initialdelay-in-scheduled-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!