简体   繁体   中英

How to check which Quartz Scheduler job is not running

I have below code which i have used to check which quartz scheduler job is running. And it also send me an email the list of running scheduler job. But i dont know its not returning all the scheduler jobs which are running.And now i want to know only those scheduler job which has issues,stopped and not running. I found critical issue in my Production environment where i found that some of the scheduler jobs are not running but i really dont know which scheduler job it is.

public String getPrintJobs() {
  StringBuilder sb = new StringBuilder();
  try {
   sb.append("Quartz Jobs\r\n\r\n");

   Scheduler scheduler = this.getJobScheduler();
         // 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> triggers = scheduler.getTriggersOfJob(jobKey);
     Date nextFireTime = null;
     int priority = 5;
              if (triggers.size() > 0)
              {
                  nextFireTime = triggers.get(0).getNextFireTime();
                  priority = triggers.get(0).getPriority();
              }

     sb.append("Name= "+ jobKey.getName() + " Group=" + jobKey.getGroup() + " NextFireTime=" + nextFireTime + " Priority=" + priority + " Paused=" + (isJobPaused(jobKey.getName())?"IS PAUSED":"NOT PAUSED") + " Triggers #=" + triggers.size() + "\r\n\r\n"); 
             }
         }

         sb.append("End Quartz Jobs\r\n\r\n");
  } catch (Exception e) {
   logger.debug("debugPrintJobs:" + e.getMessage());
  }

  return sb.toString();
 }

 private Boolean isJobPaused(String jobName) throws SchedulerException {
  Scheduler scheduler = this.getJobScheduler();
     JobKey jobKey = new JobKey(jobName);
     JobDetail jobDetail = scheduler.getJobDetail(jobKey);
     List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobDetail.getKey());
     for (Trigger trigger : triggers) {
         TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
         if (TriggerState.PAUSED.equals(triggerState)) {
             return true;
         }
     }
     return false;
 }

I haven't used it for getting any problem but the following interfaces could be helped you.

TriggerListener could check misfired when Quartz couldn't start the job.

JobListener could check completed the job which is both successful and failure cases.

http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-07.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM