Search code examples
javaquartz-schedulercronexpressioncrontrigger

How to reschedule job immediately when i update CRON expression?


Firstly when i start job my cron expression is 0 0/10 * * * ? *(For Every 10 Minutes) Eventually i have updated my cron expression to 0 0/2 * * * ? *(Updated for 2 minutes)

i want the update cron expression to take immediate effect instead of waiting until the event jobWasExecuted called.

Is it possible to reschedule as and when i update cron expression.

Thanks, Kusuma


Solution

  • I think its not achievable with CronTriggerBean. Instead you can use SimpleTriggerBean. Following is an example:

    <bean id="simpleTrigger" 
                class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    
        <property name="jobDetail" ref="runMeJob" />
        <property name="repeatInterval" value="5000" />
        <property name="startDelay" value="0" />
    
    </bean>
    

    By giving startDelay as 0 the job will start immediately the server is started. repeatInterval can be given based on your requirement.