I have an application that I would like to run when Tomcat starts the application. On first blush, I could do it by creating a servlet and in the web.xml file configure it with the <load-on-startup> parameter.
The problem is that it is not a servlet. The code is a sleeper-loop that wakes up every hour, sends a message to another web server, then goes to sleep again. No servlets used. So why do it in Tomcat? It is dependent on code that is being managed by Tomcat.
It seems a bit kludgey to create a servlet that isn't a servlet just to take advantage of the <load-on-startup> feature. Is there a better way to do this?
That seems so much better. My spider sense told me what i was doing was kludgey. I have three books, one of them specifically for Tomcat [Pro Apache Tomcat 5/5.5 From Mathew Moodie (Apress)] and there is very little about ContextListeners in print. So I Googled it - and the most helpful thing I found was http://www.onjava.com/onjava/2003/01/08/examples/ContextListener.html
Are these methods (especially contextInitialized) called asynchronously? In other words, the code will be in a near-never ending loop, waking up every few minutes, checking a directory, then going back to sleep again. In other words, do I need to worry about starting a new thread in the Listener I'm about to create so I don't hang everything up?
By the way, when i was digging through the books to look this up, I serendipitously found something else that I needed. w00t! [ October 15, 2007: Message edited by: Charles McGuire ]