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.
You may also interest at this example – list all jobs and display on JSF page.
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.
can i get whether a particular job using {jobid,groupname} is scheduled or not?
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));
}
Hi,
Can i get the list of completed job names in quartz
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.
But when you run this they have some mistakes:
Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘ncaSchedulerFactoryBean’ defined in class path resource [schedulerAppContext.xml]: Cannot create inner bean ‘ncaJobListener’ of type [com.prosodie.nca.scheduler.NcaJobListener] while setting bean property ‘listener’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘ncaJobListener’ defined in class path resource [schedulerAppContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.prosodie.nca.scheduler.NcaJobListener]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.prosodie.nca.scheduler.NcaJobListener.()
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.prosodie.nca.scheduler.StandaloneScheduler.main(StandaloneScheduler.java:46)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘ncaJobListener’ defined in class path resource [schedulerAppContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.prosodie.nca.scheduler.NcaJobListener]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.prosodie.nca.scheduler.NcaJobListener.()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
… 15 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.prosodie.nca.scheduler.NcaJobListener]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.prosodie.nca.scheduler.NcaJobListener.()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
… 19 more
Caused by: java.lang.NoSuchMethodException: com.prosodie.nca.scheduler.NcaJobListener.()
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:67)
… 20 more
Please can i help me for correct this mistakes.
Thanks
You have all better solutions in your site, thanks. How is you know enormous kind of technologies?:)