I have a Scheduler
object in my application and I add Job
s to it using the scheduleJob
method.
In my code I schedule Job
s with an instant Trigger
:
TriggerBuilder.newTrigger().startNow().build();
My question is how to tell which Job
s are scheduled into my Scheduler
? There is only a getCurrentlyExecutingJobs
method which seems unreliable so far.
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);
}
}