so many people looks for updating cron trigger with new cron expression. updating cron expression is very easy
First get the existing cron and now create new cronTrigger with the existing cron trigger details
The following code will explains how to reschedule job with new cron expression
UpdatingCronExp.java
package com.raj; /** * @author nagarajuv * */ public class UpdatingCronExp { public void updateCronExpression(org.quartz.impl.StdScheduler stdSchedular, Supplier supplier, String triggerName) { CronTrigger cronTrigger = (CronTrigger) stdSchedular.getTrigger(triggerName, groupName); String newCronExpression = "0 20 9 * * ?" try { // Creating a new cron trigger CronTrigger updatedCronTrigger = new CronTrigger(); updatedCronTrigger.setJobName(cronTrigger.getJobName()); updatedCronTrigger.setName(triggerName); updatedCronTrigger.setCronExpression(newCronExpression); // Reschedule the job with updated cron expression stdSchedular.rescheduleJob(triggerName, groupName, updatedCronTrigger); } catch (ParseException e) { e.printStackTrace(); } } }
Tags:Quartz job, Rescheduling job programatically, CronTrigger updation
0 comments:
Post a Comment