Note that there are some explanatory texts on larger screens.

plurals
  1. POTomcat fails to stop thread in webapp
    primarykey
    data
    text
    <p>In my webapp I have 3 threads where tomcat fails to stop 2 of these on reload.</p> <blockquote> <p>SEVERE: The web application [/myapp] appears to have started a thread named [Thread-8] but has failed to stop it. This is very likely to create a memory leak. mai 08, 2013 11:22:40 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads</p> </blockquote> <p>This causes the CPU usage to rise for each reload.</p> <p>Here is one of the threads that tomcat fails to stop:</p> <p>Some of the code implemented in my ServletContextListener:</p> <pre><code>public void contextInitialized(ServletContextEvent event) { final UpdaterThread updaterThread = new UpdaterThread(); updaterThread.start(); event.getServletContext().setAttribute("updaterthread", updaterThread); } public void contextDestroyed(ServletContextEvent event) { UpdaterThread updaterThread = (UpdaterThread) event.getServletContext().getAttribute("updaterthread"); if (updaterThread != null) { updaterThread.stopUpdater(); updaterThread.interrupt(); updaterThread = null; } } </code></pre> <p>And the important parts of UpdaterThread:</p> <pre><code>public class UpdaterThread extends Thread implements Runnable { private boolean alive = true; @Override public void run() { while(true) { try { while (alive) { doUpdate(); sleep(60*1000); } } catch (InterruptedException ie) {} catch (Exception e) {} } } public void stopUpdater() { alive = false; } } </code></pre> <p>Does anyone have any idea why this thread don't stops? Is there a better way to implement a thread doing some work at specific times?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload