[英]Spring scheduled task after server reboot
I'm working with @Scheduled annotation in Spring 3 . 我在Spring 3中使用@Scheduled注释。 I need to run some tasks every week or every two weeks, so i'm using cron expression as parameter eg
我需要每周或每两周运行一些任务,所以我使用cron表达式作为参数,例如
@Scheduled("0 0 2 */7 * *")
My question is if i will create scheduled task that must run every 7 days and on the 6-th day i will restart server (with war redeploy) will it reset this scheduled task (and i need to wait 7 days again) or it saves its state and will trigger this task on 7-th anyway? 我的问题是,如果我将创建必须每7天运行一次的计划任务,并且在第6天我将重新启动服务器(使用战争重新部署),它将重置此计划任务(并且我需要再次等待7天),或者保存并会在7日触发此任务?
Not sure what */7
means but I'm sure that 1/7
in the following cron means: 不知道
*/7
表示什么,但我确定以下cron中的1/7
表示:
Fires at 2am every 7 days every month starting on the first day of the month 从每月的第一天开始,每月每7天凌晨2点触发
@Scheduled("0 0 2 1/7 * ?")
I'm pretty certain it won't survive a JVM restart. 我敢肯定,JVM重启后将无法生存。
If you want the job to run every seven days you're probably better scheduling it from cron ( or similar external scheduling mechanism ) rather than getting Spring to do it. 如果您希望该作业每隔七天运行一次,则最好使用cron(或类似的外部调度机制)对其进行调度,而不是让Spring进行调度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.