首页 新闻 会员 周边

quartz 动态改变cron表达式 失败 原因oldTrigger为null 怎么解决

0
[已关闭问题] 关闭于 2016-07-19 16:03

之前一直可以用quart去改变cron表达式代码如下

TriggerKey key = TriggerKey.triggerKey(name, group);
        //表达式构建器
        CronScheduleBuilder cronSchedule = CronScheduleBuilder.cronSchedule(cron);
        CronTrigger trigger = (CronTrigger) TriggerBuilder.newTrigger().withIdentity(key).withSchedule(cronSchedule).build();
        try {
            scheduler.rescheduleJob(key, trigger);
        } catch (SchedulerException e) {
            System.out.println("更改表达式失败");
            e.printStackTrace();
        }

从某天起 就不行了 今天跟代码 发现rescheduleJob 过程中获取老触发器为null 所以未成功,但是数据库中确实存在老触发器,求解决办法

 1 /**
 2      * <p>
 3      * Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the
 4      * given name, and store the new given one - which must be associated
 5      * with the same job.
 6      * </p>
 7      * @param newTrigger
 8      *          The new <code>Trigger</code> to be stored.
 9      * 
10      * @return <code>null</code> if a <code>Trigger</code> with the given
11      *         name & group was not found and removed from the store, otherwise
12      *         the first fire time of the newly scheduled trigger.
13      */
14     public Date rescheduleJob(TriggerKey triggerKey,
15             Trigger newTrigger) throws SchedulerException {
16         validateState();
17 
18         if (triggerKey == null) {
19             throw new IllegalArgumentException("triggerKey cannot be null");
20         }
21         if (newTrigger == null) {
22             throw new IllegalArgumentException("newTrigger cannot be null");
23         }
24 
25         OperableTrigger trig = (OperableTrigger)newTrigger;
26         Trigger oldTrigger = getTrigger(triggerKey);
27         if (oldTrigger == null) {
28             return null;
29         } else {
30             trig.setJobKey(oldTrigger.getJobKey());
31         }
32         trig.validate();
33 
34         Calendar cal = null;
35         if (newTrigger.getCalendarName() != null) {
36             cal = resources.getJobStore().retrieveCalendar(
37                     newTrigger.getCalendarName());
38         }
39         Date ft = trig.computeFirstFireTime(cal);
40 
41         if (ft == null) {
42             throw new SchedulerException(
43                     "Based on configured schedule, the given trigger will never fire.");
44         }
45         
46         if (resources.getJobStore().replaceTrigger(triggerKey, trig)) {
47             notifySchedulerThread(newTrigger.getNextFireTime().getTime());
48             notifySchedulerListenersUnscheduled(triggerKey);
49             notifySchedulerListenersSchduled(newTrigger);
50         } else {
51             return null;
52         }
53 
54         return ft;
55         
56     }

26行获取到的oldTrigger为null,导致更新未成功,求解决办法

问题补充:

急求大神解决,在线等

tiger_张小虎的主页 tiger_张小虎 | 菜鸟二级 | 园豆:202
提问于:2016-07-19 12:17
< >
分享
所有回答(1)
0

解决了没?

running_wolf | 园豆:202 (菜鸟二级) | 2019-02-20 15:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册