Integration of tomcat and Quartz scheduler on startup
I would recommend the second approach as well, using a Servlet that exists only to start up some service, while a common usage, seems hacky to me.
It appears that quartz already provides a ServletContextListener for this exact purpose:
http://quartz-scheduler.org/documentation/quartz-2.x/cookbook/ServletInitScheduler
and
http://www.quartz-scheduler.org/api/2.0.0/
for details.
![DONCHEV Darko](https://lh3.googleusercontent.com/-Qm5XBlujFWo/AAAAAAAAAAI/AAAAAAAAASE/3U_bsJOt04g/photo.jpg?sz=256)
DONCHEV Darko
For last 9 years I have been working on Computer science and looks like for the rest of my life I will work on this field (though Mr. Bill Gates has mentioned that no-one is becoming rich by developing software anynore). I enjoy computer science, I am interested in developing large scale enterprise software. I have worked on all the tires of an N-tire architecture.
Updated on September 08, 2020Comments
-
DONCHEV Darko almost 4 years
I am using tomcat version 6.0. My requirement is that when tomcat starts up, I would like to start a
QuartzScheduler
which will schedule some jobs at a regular interval. I am trying to figure out the best possible way to do it. Here are the options that I could think of -- I can do this via a servlet with "
load-on-startup
" descriptor inweb.xml
file to start the scheduler and schedule the jobs inside the servlet. - Can be done using a
ContextListener
(this sounds a better approach to me than 1). This might be a clean approach to start the scheduler inside thecontextInitialized
method and shutdown the scheduler insidecontextDestroyed
method. - Using a MBean-descriptor. I develop a MBean which will get started when the server starts up with mbeans-descriptor.xml file.
To me, it looks like second approach is better. Third one might not be a good idea as it is clearly not a MBean to be monitored by jconsole or so. My purpose is to start the scheduler and stop it when tomcat stops. Is there any better and cleaner way to do this ?
- I can do this via a servlet with "
-
DONCHEV Darko about 14 yearsOpps never knew that Quartz provides a ContextListenner already. Thank you very much.