也许在 Quartz 库的某个地方有一个静态方法 triggerKey()。但是,我设法重新安排了现有的 Quartz 作业(使用 Quartz 2.3.2),而不使用这种(潜在的)方法,而是使用 TriggerKey 类,如下所示:
boolean updateExisting = true; // try it also with false
int aveId = 1234; // change it as you wish
java.util.Date closeDate = new java.util.Date(); // change it as you wish
SchedulerFactory sf = new StdSchedulerFactory("... /quartz_priority.properties");
Scheduler scheduler = sf.getScheduler();
TriggerKey triggerKey = new TriggerKey("trigger" + aveId, "group1");
if (updateExisting) {
Trigger oldTrigger = scheduler.getTrigger(triggerKey);
TriggerBuilder oldTriggerBuilder = oldTrigger.getTriggerBuilder();
Trigger newTrigger = oldTriggerBuilder.startAt(closeDate).build();
scheduler.rescheduleJob(triggerKey, newTrigger);
} else {
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(closeDate).build();
// Define job instance
JobDetail job1 = JobBuilder.newJob(<YOUR_JOB_CLASS_NAME>.class).withIdentity("job" + aveId, "group1").build();
JobDataMap map = job1.getJobDataMap();
map.put(<PARAMETER_NAME>, aveId);
// Schedule the job with the trigger
scheduler.scheduleJob(job1, trigger);
}