Spring 调度任务@scheduled学习总结

springboot技术学习 https://www.itkc8.com

工作中使用Scheduled标签,非常的便于开发,但是此标签以为不灵活,没法动态设置间隔时间,查阅标签后发现,可以设定动态时间到props中,非常方便

 

@PropertySource("classpath:root/test.props")
然后修改你的@Scheduled(cron="0/5 * *  * * ? ") 为 @Scheduled(cron="${jobs.schedule}") 
最后test.props 添加 jobs.schedule = 0/5 * *  * * ?

或者将Scheduled配置到xml中。
对于标签的使用,查阅资料复制如下:

或者将Scheduled配置到xml中。
对于标签的使用,查阅资料复制如下:

以下为复制粘贴内容:

转自:http://blog.csdn.net/kongling16688/article/details/45918833

 

1.initialDelay :初次执行任务之前需要等待的时间

@Scheduled(initialDelay =5000)
public void doSomething() {

}initialDelay =5000)
public void doSomething() {

}

 

2.fixedDelay:每次执行任务之后间隔多久再次执行该任务。

@Scheduled(fixedDelay=5000)
public void doSomething() {
    // something that should execute periodically
}
public void doSomething() {
    // something that should execute periodically
}

 

3.fixedRate:执行频率,每隔多少时间就启动任务,不管该任务是否启动完成

@Scheduled(fixedRate=5000)
public void doSomething() {

}fixedRate=5000)
public void doSomething() {

}

4.cron=“”设置时分秒等具体的定时,网上很很多相关列子。

例如:转:http://blog.csdn.net/kkdelta/article/details/7238581

 

@Scheduled(cron="*/5 * * * * MON-FRI")
public void doSomething() {
    // something that should execute on weekdays only
}
public void doSomething() {
    // something that should execute on weekdays only
}

springboot技术学习 https://www.itkc8.com

你可能感兴趣的:(springboot)