How to list all Jobs in the Quartz Scheduler

Below are two code snippets to show you how to list all Quartz jobs. Quartz 2 APIs are changed a lot, so syntax is different from Quartz 1.x.

1. Quartz 2.1.5 example


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 example


    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);

	}

    }
Note
You may also interest at this example – list all jobs and display on JSF page.

References

  1. Quartz list job cookbook

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
7 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
6 Comment authors
Alex Knopovbbq1980Kusuma ThatavarthiMagesh Babuhadjila Recent comment authors
newest oldest most voted
bbq1980
Guest
bbq1980

Hi, what are the reasons when a scheduled job is not listed? It appears, once it has been executed at least one. But when it is scheduled (e.g. starting in 6 days for the first time), it does not appear in the list.

Alex Knopov
Guest
Alex Knopov

A bit better performance can be achieved for Quartz 2.x with single loop
Set<TriggerKey> allTriggerKeys = scheduler.getTriggerKeys(GroupMatcher.anyTriggerGroup());
for (TriggerKey triggerKey: allTriggerKeys)
{
scheduledTriggers.add(scheduler.getTrigger(triggerKey));
}

Kusuma Thatavarthi
Guest
Kusuma Thatavarthi

can i get whether a particular job using {jobid,groupname} is scheduled or not?

Magesh Babu
Guest
Magesh Babu

Hi,

Can i get the list of completed job names in quartz

trackback
?? ? ??? | How To List All Jobs In The Quartz Scheduler
hadjila
Guest
hadjila

Hi yong, I’ve create class who named NcaJobListener and implement joblistener, then i would integrate this in my xml file of scheduler. This is the file xml. <?xml version="1.0" encoding="UTF-8"?> <!-- ==================================================================== SVN-Author : $LastChangedBy: cdue $ SVN-Date : $LastChangedDate: 2013-02-22 19:12:35 +0100 (Fri, 22 Feb 2013) $ SVN-Revision : $LastChangedRevision: 1201 $ SVN-Header : $HeadURL: https://svn.prosodie/NCA/trunk/NCAScheduler/src/schedulerAppContext.xml $ SVN-Id : $Id: schedulerAppContext.xml 1388 2013-03-27 08:12:22Z cdue $ ==================================================================== --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- Import NCA Batch applicationContext: mandatory to be able to run jobs usin jobLauncher. --> <import resource="applicationContext.xml"… Read more »

Armen
Guest
Armen

You have all better solutions in your site, thanks. How is you know enormous kind of technologies?:)