Spring Cron调度程序“禁用模式" [英] Spring Cron scheduler “disable pattern”
问题描述
我的应用程序从属性文件加载了一些cron模式.我使用@Scheduled
注释是这样的:
My application loads some cron patterns from a properties file. Im using the @Scheduled
annotation like this:
@Scheduled(cron = "${config.cronExpression:0 0 11,23 * * *}")
现在,我想禁用一些任务,最简单的解决方案是输入永远不会运行的cron模式. 为此,我考虑过使用仅在过去特定日期执行的cron表达式. 但是不幸的是,Spring cron表达式不允许过去添加年份或日期.
Now I want to disable some tasks and the easiest solution would be to enter a cron pattern wich will never run. In order to do this, I thought about using a cron expression that only executes at a specific day in the past. But unfortunately the Spring cron expressions don't allow to add a year or a date in the past.
有没有永远不会运行的模式?
Is there any pattern that will never run?
推荐答案
Per the Javadocs, as of Spring 5.1.0 the @Scheduled
annotation can accept "-" as the cron expression to disable the cron trigger.
特殊值-"表示已禁用的cron触发器,主要用于由$ {...}占位符解析的外部指定值.
The special value "-" indicates a disabled cron trigger, primarily meant for externally specified values resolved by a ${...} placeholder.
这篇关于Spring Cron调度程序“禁用模式"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!