I am deploying a .WAR file on Tomcat v5.5. I want to run a thread on the startup of the war file. So I am thinking of using Startup Servlet for this. But I don't have much knowledge about servlets/startup servlets. Can you guys guide me a bit on how to do it? Any descriptive links on this issues will also be much appreciated. :)
You can use a javax.servlet.ServletContextListener, and configure it in web.xml, like:
<listener>
<listener-class>com.mycompany.Listener</listener-class>
</listener>
SerletContextListeners are the correct place to initialize stuff that need the lifetime of your application. It allows you to initialize things when the application is started, and destroy stuff when the application (or app server) is shut down.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With