5

I have a Scheduler object in my application and I add Jobs to it using the scheduleJob method.

In my code I schedule Jobs with an instant Trigger:

TriggerBuilder.newTrigger().startNow().build();

My question is how to tell which Jobs are scheduled into my Scheduler? There is only a getCurrentlyExecutingJobs method which seems unreliable so far.

Adam Arold
  • 29,285
  • 22
  • 112
  • 207

1 Answers1

16

The below code list all Quartz job associated to a scheduler (Quartz 2.x.x)

for (String groupName : scheduler.getJobGroupNames()) {

 for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {

  String jobName = jobKey.getName();
  String jobGroup = jobKey.getGroup();

  //get job's trigger
  List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
  Date nextFireTime = triggers.get(0).getNextFireTime(); 

    System.out.println("[jobName] : " + jobName + " [groupName] : "
        + jobGroup + " - " + nextFireTime);

  }

}
Karthik
  • 929
  • 2
  • 12
  • 24
  • By the time of your answer I've already figured out the solution but it is the same as yours, so I'll accept it. – Adam Arold Mar 21 '14 at 19:17
  • copied from here https://www.mkyong.com/java/how-to-list-all-jobs-in-the-quartz-scheduler/ – Aadam Dec 11 '16 at 16:00