1) create a new class that implements ServletContextListener.
then implement the two methods: contextInitialized(ServletContextEvent event) and contextDestroyed(ServletContextEvent event).
example:
public final class MyContextListener implements
ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
/* This method is called when the servlet context is
initialized(when the Web Application is deployed).
You can initialize servlet context related data here.
*/
MainThread mainthread1 = new MainThread();
mainthread1.start();
}
public void contextDestroyed(ServletContextEvent event) {
/* This method is invoked when the Servlet Context
(the Web Application) is undeployed or
WebLogic Server shuts down.
*/
System.out.println("goodbye");
//thread's clean up code
}
}
Then add:
under the web-app of web.xml file.
That's it!