如何从 db 加载 cron 表达式并使用 Spring 重新安排它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32066501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to load a cron expression from db and reschedule it with Spring?
提问by Alexis B.
I'm using Spring scheduling to have batches in my application.
我正在使用 Spring 调度在我的应用程序中进行批处理。
@Scheduled(cron = "${batch.name|0 0 21 * * ?}")
public void restart() { }
Values are load from a properties file and default value from the @Scheduled annotation parameter.
值从属性文件加载,默认值来自 @Scheduled 注释参数。
Now, I would like to be able to load a cron value from database (so from an object) without using Quartz library, only with the default Spring scheduler.
现在,我希望能够在不使用 Quartz 库的情况下从数据库(因此从对象)加载 cron 值,仅使用默认的 Spring 调度程序。
Does someone know if and how it is possible?
有人知道这是否以及如何可能吗?
Thank you in advance.
先感谢您。
采纳答案by Alexis B.
I found a solution by following this : Spring @Scheduled annotation
我通过以下方法找到了解决方案: Spring @Scheduled annotation
and this : http://tutorials.jenkov.com/java-util-concurrent/scheduledexecutorservice.html
和这个:http: //tutorials.jenkov.com/java-util-concurrent/scheduledexecutorservice.html