尝试安排一个工作
// Schedule the job with the trigger
m_scheduler.scheduleJob(job, trigger);
代替
m_scheduler.scheduleJob(trigger);
From quartz-scheduler.org http://quartz-scheduler.org :
操作方法:在 2.1.x 中安排作业 http://quartz-scheduler.org/documentation/quartz-2.1.x/cookbook/ScheduleJob and 操作方法:在 2.2.x 中安排作业 http://quartz-scheduler.org/documentation/quartz-2.2.x/cookbook/ScheduleJob
两个版本的代码是相同的
// Define job instance
JobDetail job1 = newJob(ColorJob.class)
.withIdentity("job1", "group1")
.build();
// Define a Trigger that will fire "now", and not repeat
Trigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.startNow()
.build();
// Schedule the job with the trigger
sched.scheduleJob(job, trigger);
无论如何,只有当quartz无法检索到a时才会抛出异常JobDetail
触发器存储期间触发器的作业密钥storeTrigger
method
if (retrieveJob(newTrigger.getJobKey()) == null) {
throw new JobPersistenceException("The job ("
+ newTrigger.getJobKey()
+ ") referenced by the trigger does not exist.");
}
// add to triggers array
triggers.add(tw);
....
public JobDetail retrieveJob(JobKey jobKey) {
synchronized(lock) {
JobWrapper jw = jobsByKey.get(jobKey);
return (jw != null) ? (JobDetail)jw.jobDetail.clone() : null;
}
}
所以你的错误很奇怪,因为 jobkey 是之前分配的forJob
方法中的TriggerBuilder
class
public TriggerBuilder<T> forJob(JobDetail jobDetail) {
JobKey k = jobDetail.getKey();
if(k.getName() == null)
throw new IllegalArgumentException("The given job has not yet had a name assigned to it.");
this.jobKey = k;
return this;
}
尝试安排工作
m_scheduler.scheduleJob(job, trigger);
首先,按照之前的建议,如果不起作用,您应该调试代码并检查作业密钥,如果您的密钥正确,则问题可能不在您的代码中,而是石英配置不匹配。