Spring Cron 调度程序“禁用模式"

编程入门 行业动态 更新时间:2024-10-23 19:25:50
本文介绍了Spring Cron 调度程序“禁用模式"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序从属性文件加载一些 cron 模式.我正在使用这样的 @Scheduled 注释:

My application loads some cron patterns from a properties file. I'm 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 which 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?

推荐答案

从 Spring 5.1.0 开始,@Scheduled 注释可以接受 "-" 作为cron 表达式来禁用 cron 触发器.

As of Spring 5.1.0 the @Scheduled annotation can accept "-" as the cron expression to disable the cron trigger.

根据 Javadocs:

特殊值 "-" 表示禁用的 cron 触发器,主要用于由 ${...} 占位符解析的外部指定值.

The special value "-" indicates a disabled cron trigger, primarily meant for externally specified values resolved by a ${...} placeholder.

这篇关于Spring Cron 调度程序“禁用模式"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-27 04:45:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/679065.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   程序   Spring   Cron   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!