I called the MyListener class from the web.xml file
<listener>
<listener-class>MyListener</listener-class>
</listener>
import javax.servlet.*;
public class MyListener implements ServletContextListener{
public void contextInitialized(ServletContextEvent event) {
try{
(new Thread(new SampleProcessor())).start();
}catch(Exception e){e.printStackTrace();}
}
public void contextDestroyed(ServletContextEvent arg0) {}
}
public class SampleProcessor implements Runnable{
public void run(){
//Here we write the code for listening to a JMS Topic
}
} I have another listener similar to above which is listening to another JMS Topic. When I stop the server I am getting the following errors on Server Error 1: "The web application [/MyServlet] appears to have started a thread named [thread-1] but has failed to stop it. This is very likely to create a memory leak." Error 2: "The web application [/MyServlet] appears to have started a thread named [thread-2] but has failed to stop it. This is very likely to create a memory leak."
Why is the error happening and how we can stop the threads or how can we fix it?