【问题标题】:How do I maintain values between spring task scheduled如何在预定的春季任务之间维护值
【发布时间】:2017-02-09 17:49:44
【问题描述】:

我想在 spring task:scheduled 之间保持值,例如我的 cron 是每隔一小时触发一次。

<task:scheduled-tasks>
<task:scheduled ref="runScheduler" method="run" cron="0 0 * * * *" />
</task:scheduled-tasks>

我想知道,如何在下一个 cron 线程上从上一小时的 cron 线程中获取值。

【问题讨论】:

    标签: java spring cron spring-batch


    【解决方案1】:

    Cron 属性与@Scheduled 注释一起使用。此属性的值必须是 cron 表达式。此 cron 表达式将在属性文件中定义,相关属性的键将在 @Scheduled 注释中使用。

    <task:scheduled-tasks>
    <task:scheduled ref="runScheduler" method="run" cron="#{applicationProps['cron.expression']}" />
    </task:scheduled-tasks>
    

    然后使用@Scheduled(cron = "${cron.expression}") 注解。

    以下链接可能对您有所帮助:

    http://howtodoinjava.com/spring/spring-core/4-ways-to-schedule-tasks-in-spring-3-scheduled-example/

    【讨论】:

    • 我的澄清是,让我们说,根据 cron,该作业在上午 9 点触发并持有一些值,下一个作业是在上午 10 点,并且希望在上午 10 点作业中获得上午 9 点作业的值。我该怎么做?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 1970-01-01
    相关资源
    最近更新 更多