下面是兩個程式碼片段展示如何列出所有Quartz的作業。Quartz2 API都發生了很大變化,所以語法和Quartz1.x是不同的
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); } }
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); } }