2016-11-16 213 views
1

我正在向石英調度程序添加作業。之後,我打電話給附加的調試打印作業功能。它沒有列出工作。對getCurrentlyExecutingJobs()的函數調用可能僅限於返回最大值。 10個工作?石英調度程序丟失作業

public void scheduleManagementEmail(ManagementEmailConfig managementEmailConfig, Scheduler scheduler) throws SchedulerException 
{ 
    logger.debug("Scheduling Management Email " + 
    managementEmailConfig.getManagementEmailConfigId()); 

    String jobKey = "SendManagementEmailJob_" +  
    managementEmailConfig.getManagementEmailConfigId(); 
    Class<? extends Job> jobClass = SendManagementEmailJob.class; 
    JobDetail job = JobBuilder.newJob(jobClass).withIdentity(new JobKey(jobKey)).build(); 
    Trigger trigger = sendManagementEmailJob.getTriggerWithSchedule(managementEmailConfig); 
    trigger.getJobDataMap().put("managementEmailConfigId", managementEmailConfig.getManagementEmailConfigId()); 
    if (!scheduler.checkExists(new JobKey(jobKey))) 
    { 
     scheduler.scheduleJob(job, trigger); 
    } 
    debugPrintJobs(); 
} 

public void debugPrintJobs() { 
    try { 
     logger.debug("Quartz Jobs"); 
     Scheduler s_scheduler = this.getJobScheduler(); 
     List<JobExecutionContext> currentJobs = s_scheduler.getCurrentlyExecutingJobs(); 
    for (JobExecutionContext jobCtx : currentJobs) { 
     JobKey jobKey = jobCtx.getJobDetail().getKey();    
     JobDetail jobDetail = s_scheduler.getJobDetail(jobKey); 
     List<? extends Trigger> triggers = s_scheduler.getTriggersOfJob(jobKey); 

     Date nextFireTime = null; 
     if (triggers.size() > 0) 
     { 
      nextFireTime = triggers.get(0).getNextFireTime(); 
     } 
     logger.debug("Name= "+ jobKey.getName() + " Group=" + jobKey.getGroup() + " NextFireTime=" + nextFireTime); 
    } 
} catch (Exception e) { 
    logger.debug("debugPrintJobs:" + e.getMessage()); 
} 
+1

「我增加了作業調度石英。」不在您向我們展示的代碼中。 – 2016-11-16 08:29:13

+0

你能否改進你的代碼的縮進?這是非常難以閱讀。 – 2016-11-16 08:39:29

回答

1

方法getCurrentlyExecutingJobs()將只返回正在運行的作業,而不是每個計劃作業。
讓每一個計劃的作業,你應該做這樣的事情:

Scheduler scheduler = getScheduler(); 
    try { 
     // All scheduled jobs 
     for (String groupName : scheduler.getJobGroupNames()) { 
      for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { 
       JobDetail jobDetail = scheduler.getJobDetail(jobKey); 
       final List<? extends Trigger> triggersOfJob = scheduler.getTriggersOfJob(jobKey); 
       // Do something with the info you just got 
       // ... 
      } 
     } 
    } catch (SchedulerException e) { 
     log.error("Retrieving jobs", e); 
    }