在Spring中使用相同的工作详细信息动态地重新计划CronTriggerBean [英] Rescheduling a CronTriggerBean dynamically with same job details in Spring

查看:183
本文介绍了在Spring中使用相同的工作详细信息动态地重新计划CronTriggerBean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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>

我正在使用以下代码从控制器动态更改cron表达式.但这不起作用.

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.

谢谢

-Anil Kumar.C

-Anil Kumar.C

推荐答案

spring论坛上有一个关于此的主题,它暗示他们找到了解决您问题的方法:

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

但是,除了手动更改文件中的cron表达式外,您还可以使用spring表达式语言每次从持有该值的对象中读取它.

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.

这篇关于在Spring中使用相同的工作详细信息动态地重新计划CronTriggerBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆