本文整理匯總了Java中org.quartz.Scheduler.rescheduleJob方法的典型用法代碼示例。如果您正苦於以下問題:Java Scheduler.rescheduleJob方法的具體用法?Java Scheduler.rescheduleJob怎麽用?Java Scheduler.rescheduleJob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.quartz.Scheduler
的用法示例。
在下文中一共展示了Scheduler.rescheduleJob方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: modifyJobTime
import org.quartz.Scheduler; //導入方法依賴的package包/類
/**
* @Description: 修改一個任務的觸發時間(使用默認的任務組名,觸發器名,觸發器組名)
* @param jobName
* @param time
*
*/
@SuppressWarnings("unchecked")
public static void modifyJobTime(String jobName, String time) {
TriggerKey triggerKey = TriggerKey.triggerKey(
jobName, TRIGGER_GROUP_NAME);
try {
Scheduler sched = gSchedulerFactory.getScheduler();
CronTrigger trigger =(CronTrigger) sched.getTrigger(triggerKey);
if (trigger == null) {
return;
}
String oldTime = trigger.getCronExpression();
if (!oldTime.equalsIgnoreCase(time)) {
CronScheduleBuilder scheduleBuilder =CronScheduleBuilder.cronSchedule(time);
//按新的cronExpression表達式重新構建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey)
.withSchedule(scheduleBuilder).build();
//按新的trigger重新設置job執行
sched.rescheduleJob(triggerKey, trigger);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: updateJobTrigger
import org.quartz.Scheduler; //導入方法依賴的package包/類
@Transactional
@Override
public boolean updateJobTrigger(ScheduleJobEntity job) {
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
// 獲取觸發器標識
TriggerKey triggerKey = job.getTriggerKey();
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// Trigger已存在,更新相應的定時設置
// 表達式調度構建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
.cronSchedule(job.getCronExpression());
// 按新的cronExpression表達式重新構建trigger
trigger = trigger.getTriggerBuilder()
.forJob(job.getJobKey())
.withIdentity(triggerKey)
.startAt(job.getStartDate()) // job開始日期
.endAt(job.getEndDate())// job結束日期
.withSchedule(scheduleBuilder).build();
// 按新的trigger重新設置job執行
scheduler.rescheduleJob(triggerKey, trigger);
return Boolean.TRUE;
} catch (Exception e) {
throw new ServiceException(e);
}
}
示例3: updateScheduleJob
import org.quartz.Scheduler; //導入方法依賴的package包/類
/**
* 更新定時任務
*/
public static void updateScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
try {
TriggerKey triggerKey = getTriggerKey(scheduleJob.getJobId());
//表達式調度構建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
.withMisfireHandlingInstructionDoNothing();
CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getJobId());
//按新的cronExpression表達式重新構建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
//參數
trigger.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, new Gson().toJson(scheduleJob));
scheduler.rescheduleJob(triggerKey, trigger);
//暫停任務
if(scheduleJob.getStatus() == ScheduleStatus.PAUSE.getValue()){
pauseJob(scheduler, scheduleJob.getJobId());
}
} catch (SchedulerException e) {
throw new RRException("更新定時任務失敗", e);
}
}
示例4: updateTriggerForJob
import org.quartz.Scheduler; //導入方法依賴的package包/類
/**
* 更新Trigger
* @param schedulerName
* @param trigger
* @throws SchedulerException
*/
public void updateTriggerForJob(String schedulerName, Trigger trigger) throws SchedulerException {
Assert.notNull(trigger, "trigger can not be null");
Scheduler scheduler = this.getAssertScheduler(schedulerName);
if (existTrigger(schedulerName, QuartzUtils.getTriggerName(trigger), QuartzUtils.getTriggerGroup(trigger))) {
scheduler.rescheduleJob(trigger.getKey(), trigger);
} else {
throw new IllegalArgumentException("trigger [" + trigger.getKey().getName() +
":" + trigger.getKey().getGroup() + "] not exist");
}
}
示例5: updateJobCron
import org.quartz.Scheduler; //導入方法依賴的package包/類
/**
* 更新job時間表達式
*
* @param scheduleJob
* @throws SchedulerException
*/
public void updateJobCron(ScheduleJob scheduleJob) throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
scheduler.rescheduleJob(triggerKey, trigger);
}
示例6: updateJobCron
import org.quartz.Scheduler; //導入方法依賴的package包/類
/**
* 更新job時間表達式
*
* @param scheduleJob
* @throws SchedulerException
*/
public void updateJobCron(ScheduleJob scheduleJob) throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getName(), scheduleJob.getGroup());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCron());
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
scheduler.rescheduleJob(triggerKey, trigger);
}