在 Spring 中使用相同的作业详细信息动态重新安排 CronTriggerBean

发布于 2024-10-14 05:35:15 字数 1462 浏览 2 评论 0原文

我的任务是按照用户从 GUI 指定的计划时间动态生成报告。

我在 Spring 应用程序的应用程序上下文中使用以下代码来每天早上 6 点生成报告。

<bean name="scheduleRptJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="com.secant.qatool.report.scheduler.ScheduleCroneJob"/>
</bean>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="scheduleRptJob" />

<bean id="schedulerFactory"  class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronTrigger"/>
        </list>
    </property>
</bean>

我使用以下代码从控制器动态更改 cron 表达式。但它不起作用。

    String time[] = rptScheduleTime.split(":");

    String hours = time[0];
    String minutes = time[1];

    String croneExp = " 00 " + minutes + " " + hours + " * * ? ";

    log.debug("CRONE EXP :: " + croneExp);

    cronTrigger.clearAllTriggerListeners();

    // Setting the crown expression.
    cronTrigger.setCronExpression(croneExp);

    Trigger[] triggers = {cronTrigger};

    // Code to pause and start the cron trigger.
    schedulerFactory.stop();
    schedulerFactory.setTriggers(triggers);
    schedulerFactory.start();

有人可以帮我如何用动态时间重新安排同一份工作吗?

谢谢,

-Anil Kumar.C

My task is to generate the reports dynamically with the scheduled time specified by the user from the GUI.

I am using the following code in the application context of my application in spring to generate the report daily 6 A.M..

<bean name="scheduleRptJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="com.secant.qatool.report.scheduler.ScheduleCroneJob"/>
</bean>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="scheduleRptJob" />

<bean id="schedulerFactory"  class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronTrigger"/>
        </list>
    </property>
</bean>

I am changing the cron expression dynamically from the controller with the following code. But it is not working.

    String time[] = rptScheduleTime.split(":");

    String hours = time[0];
    String minutes = time[1];

    String croneExp = " 00 " + minutes + " " + hours + " * * ? ";

    log.debug("CRONE EXP :: " + croneExp);

    cronTrigger.clearAllTriggerListeners();

    // Setting the crown expression.
    cronTrigger.setCronExpression(croneExp);

    Trigger[] triggers = {cronTrigger};

    // Code to pause and start the cron trigger.
    schedulerFactory.stop();
    schedulerFactory.setTriggers(triggers);
    schedulerFactory.start();

Could someone please help me how to reschedule the same job with dynamic time.

Thanks,

-Anil Kumar.C

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2024-10-21 05:35:15

春季论坛中有一个关于此问题的帖子,他们似乎为您的问题找到了解决方案: http://forum.springsource.org/showthread.php?t=31736

但您可以使用 spring 表达式语言每次从持有 的对象中读取它,而不是手动更改文件中的 cron 表达式价值。

there is a thread in the spring forum about this, and it seams they found a solution for your problem: http://forum.springsource.org/showthread.php?t=31736

but instead of manually change the cron expression in the file you could use the spring expression language to read it each time from your object holding the value.

热鲨 2024-10-21 05:35:15

我发现 这个 线程在其中读取了 cron expr从数据库中获取,然后重新安排作业。您只是不会从数据库读取它,而是根据需要直接从 GUI 传递它。

I have found this thread where they read a cron expr from DB and then reschedule the job. You just wouldn't read it from DB, but pass it directly from GUI as you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文