[英]How to change Spring's @Scheduled fixedDelay at runtime?
[英]How to disable Spring's @Scheduled fixedDelay
我正在使用@Scheduled(fixedDelay = 60000)
在 Spring Boot 应用程序中运行一个函数。
现在,我希望调度程序仅在生产环境中运行(不应该在开发环境中运行)。
如果是cron
,我可以做类似@Scheduled(cron = "${someProperty}")
的事情,并为开发环境制作someProperty="-"
。
fixedDelay
有没有类似的方法?
您可以输入一个负值来禁用该字段。 但是,Spring 恰好需要存在fixedDelay
、 cron
或fixedRate
之一。
我建议您为 cron 和fixedDeplay
使用 2 个变量以获得想要的效果
@Scheduled(fixedDelay = 1000, cron = "") // for enable it
@Scheduled(fixedDelay = -1, cron = "-") // for disable it
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.