I’m having trouble to understand how to use Quartz with QuartzInitializerListener.
First I declare that listener in deployment descriptor. But then, how to I add my jobs? Taking a look at QuartzInitializerListener implementation, I see it creates the SchedulerFactory and Scheduler, but I don’t see any way to add jobs. The factory receives a configuration file, but again there’s nothing related to the jobs there.
I only found very simples examples from my searches, all about instantiating everything in main method.
Can anyone point me to a more real example? I’m using JBoss 5 if that matters. Thanks.
Everything is described in the source code Javadoc you quote:
EDIT: This means that when you are using this listener you can obtain
SchedulerFactoryinside every servlet/Spring MVC controller/… by running:Note that context listeners are guaranteed to be executed before any servlet is used to handle incoming requests. This means that the scheduler will always be properly initialized prior to its usage.
Summary of the discussion in the comments below, the discussion actually answers the question being asked:
If you want to add jobs at application startup, write another listener (similar to the one provided by Quartz), lookup StdSchedulerFactory (ServletContext is easily available) and do what you want. The listeners are guaranteed to execute in the same order as they are declared in web.xml, so put your listener after Quartz one.