0
所以,我想將觸發器的特定值傳遞給作業。看起來這個值被覆蓋併產生最後一個值。如何將觸發器列表中的同一個鍵的不同值傳遞給作業?
public void createControlTask(String name, String id, String freq) throws SchedulerException {
JobBuilder jobBuilder;
JobDetail jobDetail;
TriggerBuilder trigBuilder;
Trigger trigger = null;
Set<Trigger> triggerList = new HashSet<Trigger>();
String[] months = null;
String cronFreq;
//Get current year from properties file -- kavitha
String year = props.getProperty("task.year");
log.info("in createSchedulerTask() for : [" + name + "] id [" + id + "] freq [" + freq + "]");
// Consider the control only if the frequency is monthly, quarterly, semi-annually or annually
if ((freq != null) && !(freq.equals(Constants.AS_NEEDED))) {
jobBuilder = JobBuilder.newJob(QuraJob.class);
jobBuilder = jobBuilder.withIdentity(name + "_JOB", Constants.CONTROL_TASK);
jobBuilder = jobBuilder.usingJobData(Constants.NAME, name);
jobBuilder = jobBuilder.usingJobData(Constants.ID, id);
jobBuilder = jobBuilder.usingJobData(Constants.FREQUENCY, freq);
jobDetail = jobBuilder.build();
log.info("Job created -- [" + jobDetail.getKey() + "]");
if(freq.equals(Constants.MONTHLY)){
months = Constants.MONTHLY_PERIOD;
}
if(freq.equals(Constants.QUARTERLY)){
months = Constants.QUARTERLY_PERIOD;
}
if(freq.equals(Constants.ANNUAL)){
months = Constants.ANNUAL_PERIOD;
}
if(freq.equals(Constants.SEMI_ANNUALLY)){
months = Constants.SEMI_ANNUALLY_PERIOD;
}
for(int i = 0; i < months.length; i++){
cronFreq = props.getProperty(Constants.PID_CRON_CONTROLTASK + months[i]);
trigBuilder = TriggerBuilder.newTrigger();
trigBuilder = trigBuilder.withIdentity(name + "_TRIGGER_" + i, Constants.CONTROL_TASK);
trigBuilder = trigBuilder.startNow();
trigBuilder = trigBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cronFreq));
//Add year and month (Eg: "January-2016") as job data
**這是我將數據發送到JOB ** jobDetail.getJobDataMap()把(Constants.TASK_MONTH_YEAR,幾個月[I] + 「 - 」 +年)。
trigBuilder = trigBuilder.forJob(jobDetail);
trigger = trigBuilder.build();
//add the trigger to a list
triggerList.add(trigger);
}
if(triggerList.size() > 0){
//schedule the triggerlist to the job created, false -- if any of job & trigger id already exists, throws exception
scheduler.scheduleJob(jobDetail,triggerList,false);
}
}
else
log.info("Freq [" + freq + "] is not a schedulable value. So not scheduling a task for this control");
}