java

How to use ContextLoaderListener,how to make application Listener

publicclass Main extends org.springframework.web.context.ContextLoaderListener {

 /**

*@param args

*/

DatabaseListner listener = new DatabaseListner();

publicvoid contextDestroyed(ServletContextEvent event) {

super.contextDestroyed(event);

listener.end();

listener = null;

System.out.println(“web app undeployed”);

}

publicvoid contextInitialized(ServletContextEvent event) {

super.contextInitialized(event);

new Thread(){

publicvoid run() {

listener.listen();

}

}.start();

System.out.println(“Web app is ready.”);

}

}

and add those lines to servlet at web.xml

<listener>
<listener-class>com.amazon.synchronizer.Main</listener-class>
</listener>

Advertisements