Reputation: 683
I have a following scenario.
suppose in web application there is folder called dump in which data logs files are created. i am restarting my web server (apache tomcat). so before my web application start or ready to serve the request. it should execute some program and fetches the data from logs file and need to insert into table.
I know we can do something like that using Interceptors in struts2 /spring mvc or using Servlet making load-on-startup. but it will execute when the server is ready to request. i want to execute above program while web server is going to initialised and before web application is started.
Upvotes: 0
Views: 151
Reputation: 4296
You could use the Context Listener, provided for by the JavaEE spec: http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html#contextInitialized(javax.servlet.ServletContextEvent)
contextInitialized(), specifically will be an event that you want to operate on.
However, you may want to be sure about what resources are initialized/ready for you to use at this phase.
Upvotes: 2