org.quartz.JobPersistenceException: The job (group.name) referenced by the trigger does not exist.

异常:

org.quartz.JobPersistenceException: The job (jobGroup.jobName) referenced byorg.quartz.JobPersistenceException: The job (xxxxxx.xxxxxxxx) referenced by the trigger does not exist.
    at org.quartz.simpl.RAMJobStore.storeTrigger(RAMJobStore.java:422)
    at org.quartz.core.QuartzScheduler.triggerJob(QuartzScheduler.java:1162)
    at org.quartz.impl.StdScheduler.triggerJob(StdScheduler.java:341)
    at org.quartz.impl.StdScheduler.triggerJob(StdScheduler.java:331)
    at com.bmw.afs.task.quartz.init.InitQuartzJob.triggerJob(InitQuartzJob.java:165)

产生场景:

配置好quartz定时任务,调用报错。

产生原因:前台页面配置的jobGroup和jobName和数据库存储的不一致,导致报错,原因代码如下:

public void storeTrigger(OperableTrigger newTrigger, boolean replaceExisting) throws JobPersistenceException {
        TriggerWrapper tw = new TriggerWrapper((OperableTrigger)newTrigger.clone());
        synchronized(this.lock) {
            if (this.triggersByKey.get(tw.key) != null) {
                if (!replaceExisting) {
                    throw new ObjectAlreadyExistsException(newTrigger);
                }

                this.removeTrigger(newTrigger.getKey(), false);
            }

            if (this.retrieveJob(newTrigger.getJobKey()) == null) {
                throw new JobPersistenceException("The job (" + newTrigger.getJobKey() + ") referenced by the trigger does not exist.");
            } else {
                List jobList = (List)this.triggersByJob.get(tw.jobKey);
                if (jobList == null) {
                    jobList = new ArrayList(1);
                    this.triggersByJob.put(tw.jobKey, jobList);
                }

产生错误代码为:

throw new JobPersistenceException("The job (" + newTrigger.getJobKey() + ") referenced by the trigger does not exist.");

解决办法: 

由报错可知,错误出现在类RAMJobStore,找到对应代码,调试即可知道解决办法,jobGroup和jobName和数据库配置保持一致。

补充:

后来通过排查发现了问题的真正原因,理论上来说,这个定时任务会有一个前端页面显示数据库数据,基本不会出现数据不一致的情况。

通过实践,发现真正需要定时任务起作用,因为是在数据库直接添加的定时任务,真正生效还需要重启工程。

你可能感兴趣的:(Java)