Quartz列出调度器所有作业 - Quartz教程
下面是两个代码片段展示如何列出所有Quartz的作业。Quartz2 API都发生了很大变化,所以语法和Quartz1.x是不同的
1. Quartz 2.2.1 示例
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
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);
}
}
2. Quartz 1.8.6 示例
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
//loop all group
for (String groupName : scheduler.getJobGroupNames()) {
//loop all jobs by groupname
for (String jobName : scheduler.getJobNames(groupName)) {
//get job's trigger
Trigger[] triggers = scheduler.getTriggersOfJob(jobName,groupName);
Date nextFireTime = triggers[0].getNextFireTime();
System.out.println("[jobName] : " + jobName + " [groupName] : "
+ groupName + " - " + nextFireTime);
}
}