Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Spring Context not gracefully closed?
    primarykey
    data
    text
    <p>On <code>stop</code> or <code>undeploy/redeploy</code> of a <code>Spring framework 3.0.5</code> based web application following error is logged in <code>Tomcat7's catalina.out</code>:</p> <pre><code>SEVERE: The web application [/nomination##1.0-qa] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4f43af8f]) and a value of type [org.springframework.security.core.context.SecurityContextImpl] (value [org.springframework.security.core.context.SecurityContextImpl@ffffffff: Null authentication]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. </code></pre> <p>I initially thought of implementing <code>ServletContextListener</code> and <code>close()</code> the context there. However, found <code>ContextLoaderListener</code> which implements <code>ServletContextListener</code> is set up like so in <code>web.xml</code>:</p> <pre><code>&lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; </code></pre> <p>From Javadocs:</p> <pre><code>**contextDestroyed** public void contextDestroyed(ServletContextEvent event) Close the root web application context. Specified by: contextDestroyed in interface ServletContextListener </code></pre> <p>So, my question is why the ThreadLocal not cleanly freed by <code>ContextLoaderListener.contextDestroyed()</code>?</p> <p>We are running into <code>PermGen</code> errors and while investigating found this. There is code similar to the following in a few places:</p> <pre><code>ApplicationContext context = WebApplicationContextUtils .getWebApplicationContext(se.getSession().getServletContext()); MyBeanClass x = context.getBean( "myBean", MyBeanClass.class); x.someMethod(); </code></pre> <p>I wonder if the above snippet is stopping a clean shutdown? Any pointers will be greatly appreciated.</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.
    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