开发者

Rescheduling a CronTriggerBean dynamically with same job details in Spring

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 = tim开发者_如何学Ce[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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜