Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Startup Servlet for WAR File

Tags:

java

servlets

war

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. :)

like image 490
Vishal Avatar asked Dec 07 '25 09:12

Vishal


1 Answers

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.

like image 174
Jesse Avatar answered Dec 08 '25 21:12

Jesse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!