You should setUp/tearDown Quartz's Scheduler using context listener in your web application and attach it to your Application Context.
-----Original Message----- From: Ernesto Reinaldo Barreiro [mailto:[email protected]] Sent: Thursday, December 11, 2008 6:41 PM To: [email protected] Subject: Re: Integrating Scheduler into Web Application Hi Will, Maybe this is more question for the quartz mailing list.... Probably you would want to have only one scheduler per application, so you should follow a singleton pattern. E.g. public class SchedulerLocator { private static Scheduler scheduler; public static Scheduler getScheduler() { if(scheduler == null) { scheduler = .....all the factory thing. } return scheduler; } } So everywhere you could do SchedulerLocator.getScheduler() (e.g on you pages). I would "create" this singleton when the application object is created or initialized. init() { SchedulerLocator.getScheduler(); } If you want your jobs/triggers to persist after application restarts you will need to create a "persistent" scheduler and consequently create the associated tables and instruct quartz to deal with them... Ernesto wfroud wrote: > Hi, > > I am trying to integrate a scheduler into my web application. I believe my > question is probably very trivial but I am missing some vital Java > knowledge. Please let me explain… > My web application currently allows users to choose, customise and run > reports. > I now need to add a detailed scheduler so that users can choose when to run > the reports and how often etc. > > I'm using Spring for the db access, and I was going to use Quartz for > scheduling. > > A basic Quartz schedule looks something like the following: > public class SimpleExample { > > public void run() throws Exception { > > // First we must get a reference to a scheduler > // This schedule info is stored in a db, defined in the > quartz.properties file. > SchedulerFactory sf = new StdSchedulerFactory(); > Scheduler sched = sf.getScheduler(); > > // Add jobs and triggers to schedule. > > // Start up the scheduler (nothing can actually run until the > // scheduler has been started) > sched.start(); > > // Wait for a short period of time so scheduler has chance to run > jobs. > > sched.shutdown(); > } > > public static void main(String[] args) throws Exception { > > SimpleExample example = new SimpleExample(); > example.run(); > > } > > } > > More details about a really basic example can be found here: > http://wiki.opensymphony.com/display/QRTZ1/TutorialLesson1 > > I can run this fine as a standalone test. > > The basics of my web application are as follows: > > MyApp which extends WebApplication. > Loads of classes which extend WebPage > A MySession class which extends WebSession > > What I'm not sure about is where I should be instantiating the > SchedulerFactory within my application so that all users can update any > schedule (i.e. so there is kind-of-like global access to the scheduler > object) and so that the SchedulerFactory is only instantiated the once. > > I can't instantiate it in a web page as this will be user specific. > I could instantiate it in the MyApp class but then I don't have access to it > from the web pages. > > Any help whatsoever, just to point me in the right direction, would be much > appreciated. > > Thanks > > Will > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] *************************************************************************************************** "Atenção: Esta mensagem foi enviada para uso exclusivo do(s) destinatários(s) acima identificado(s), podendo conter informações e/ou documentos confidencias/privilegiados e seu sigilo é protegido por lei. Caso você tenha recebido por engano, por favor, informe o remetente e apague-a de seu sistema. Notificamos que é proibido por lei a sua retenção, disseminação, distribuição, cópia ou uso sem expressa autorização do remetente. Opiniões pessoais do remetente não refletem, necessariamente, o ponto de vista da CETIP, o qual é divulgado somente por pessoas autorizadas." "Warning: This message was sent for exclusive use of the addressees above identified, possibly containing information and or privileged/confidential documents whose content is protected by law. In case you have mistakenly received it, please notify the sender and delete it from your system. Be noticed that the law forbids the retention, dissemination, distribution, copy or use without express authorization from the sender. Personal opinions of the sender do not necessarily reflect CETIP's point of view, which is only divulged by authorized personnel." ***************************************************************************************************
