jos*_*t91 5 java quartz-scheduler
我在成功调度作业时遇到了一些问题而没有得到标题中提到的错误,具体来说: The job (CRAWLS.my_repos) referenced by the trigger does not exist. [See nested exception: org.quartz.JobPersistenceException: The job (CRAWLS.my_repos) referenced by the trigger does not exist.]
这里看一下代码......其中一切看起来都应该没问题.
runJob方法......需要注意的主要问题是它在这一行中失败了:m_scheduler.scheduleJob(trigger);方法的其余部分是存在的,以防其余部分有用.
public void runJob(JobInfo jobInfo,
com.lawson.search.spi.common.Properties jobProperties)
{
try {
JobDataMap jobDataMap = QuartzUtils.createJobDataMapFromLesProperties(jobProperties);
if (jobExists(jobInfo)) {
m_scheduler.triggerJob(jobKey(jobInfo.getName(), jobInfo.getGroup()), jobDataMap);
} else {
JobDetail job = QuartzUtils.createJobDetailFromJobInfo(jobInfo);
Trigger trigger = newTrigger()
.forJob(job)
.withIdentity(getImmediateTriggerName(jobInfo))
.build();
m_scheduler.scheduleJob(trigger);
}
} catch (SchedulerException e) {
String msg = "runJob: " + jobInfo;
if (s_log.isDebugEnabled()) {
s_log.debug(msg, e);
}
throw new JobSchedulerException(msg, e);
}
}
Run Code Online (Sandbox Code Playgroud)
该createJobDetailFromJobInfo()方法简单,但很重要:
static JobDetail createJobDetailFromJobInfo(JobInfo theJobInfo)
{
JobDetail detail = newJob(QuartzJobAdapter.class)
.withIdentity(theJobInfo.getName(), theJobInfo.getGroup())
.storeDurably()
.build();
return detail;
}
Run Code Online (Sandbox Code Playgroud)
我能想到的唯一另一个重要的方法是我getImmediateTriggerName()认为可能导致问题的方法......但我不知道为什么.
private String getImmediateTriggerName(JobInfo jobInfo)
{
return jobInfo.getName() + "#" + jobInfo.getGroup() + ":" + System.currentTimeMillis();
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
vza*_*llo 10
尝试安排一份工作
// Schedule the job with the trigger
m_scheduler.scheduleJob(job, trigger);
Run Code Online (Sandbox Code Playgroud)
代替
m_scheduler.scheduleJob(trigger);
Run Code Online (Sandbox Code Playgroud)
方法:在2.1.x中安排作业和操作方法:在2.2.x中安排作业
两个版本的代码相同
// 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);
Run Code Online (Sandbox Code Playgroud)
无论如何,只有当quartz JobDetail在storeTrigger方法的触发器存储期间无法为触发器的jobkey 检索a时,才会抛出异常
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);
Run Code Online (Sandbox Code Playgroud)
....
public JobDetail retrieveJob(JobKey jobKey) {
synchronized(lock) {
JobWrapper jw = jobsByKey.get(jobKey);
return (jw != null) ? (JobDetail)jw.jobDetail.clone() : null;
}
}
Run Code Online (Sandbox Code Playgroud)
所以你的错误很奇怪,因为jobkey是先前在类中的forJob方法分配的TriggerBuilder
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;
}
Run Code Online (Sandbox Code Playgroud)
尝试安排工作
m_scheduler.scheduleJob(job, trigger);
Run Code Online (Sandbox Code Playgroud)
首先,如前所述,如果不起作用,您应该调试代码并检查作业键,如果您的键是正确的,可能问题不在您的代码中,并且是石英配置不匹配.
| 归档时间: |
|
| 查看次数: |
8162 次 |
| 最近记录: |