Java Web application initialization and shutdown
I try to initialize and close a webapp Including initialization and shutdown:
> Hibernate(v3.6); > C3P0(v0.9.1.2); > EHCache(v2.3.0); Quartz (1.8.4); > Other tasks unique to my webapp;
Using Tomcat 5.5 30 and Java 6 My idea is to avoid resource leakage, mainly because webapp is redeployed in the development environment
How can I achieve it?
Solution
Usually, for web initialization and shutdown, you will write a servletcontextlistener
The steps to perform this operation are as follows:
>Write an implementation of javax Servlet. Servletcontextlistener's class > add a tag to the web XML deployment descriptor to register the class you just created > deploy application
When the application is deployed, the contextinitialized method is called You can place all initialization here The contextdestroyed method is called when the application closes