Migrating a CronTriggerBean dynamically with identical jobs in Spring

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

I use the following code in the application context of my application in spring to generate a 6 AM report daily.

<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 modifying a cron expression dynamically from a controller using the following code. But it does not work.

    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();

Can someone please help me how to transfer the same work with dynamic time.

Thank,

-Anil Kumar.C

+3
source share
2 answers

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

, cron , spring, , .

+4

, cron expr . , , .

+1

Source: https://habr.com/ru/post/1787374/


All Articles