protected boolean triggerExists(Trigger checkTrigger) {
   try {
     Trigger trigger =
         resourceScheduler.getTrigger(checkTrigger.getName(), checkTrigger.getGroup());
     return (trigger != null);
   } catch (SchedulerException e) {
     log.error("Failed to check if the trigger exists", e);
   }
   return false;
 }
 protected boolean triggerChanged(Trigger checkTrigger) {
   try {
     Trigger trigger =
         resourceScheduler.getTrigger(checkTrigger.getName(), checkTrigger.getGroup());
     if (trigger != null && trigger instanceof CronTrigger) {
       return !((CronTrigger) trigger)
           .getCronExpression()
           .equals(((CronTrigger) checkTrigger).getCronExpression());
     }
   } catch (SchedulerException e) {
     log.error("Failed to check if the trigger has changed", e);
   }
   return false;
 }
Exemple #3
0
 /**
  * 从Scheduler 移除当前的Job,修改Trigger
  *
  * @param jobDetail
  * @param time
  * @throws SchedulerException
  * @throws ParseException
  */
 public static void modifyJobTime(JobDetail jobDetail, String time)
     throws SchedulerException, ParseException {
   Scheduler sched = sf.getScheduler();
   Trigger trigger = sched.getTrigger(jobDetail.getName(), TRIGGER_GROUP_NAME);
   if (trigger != null) {
     CronTrigger ct = (CronTrigger) trigger;
     // 移除当前进程的Job
     sched.deleteJob(jobDetail.getName(), jobDetail.getGroup());
     // 修改Trigger
     ct.setCronExpression(time);
     System.out.println("CronTrigger getName " + ct.getJobName());
     // 重新调度jobDetail
     sched.scheduleJob(jobDetail, ct);
   }
 }