memory leaks - Why Spring Context not gracefully closed? -
on stop
or undeploy/redeploy
of spring framework 3.0.5
based web application following error logged in tomcat7's catalina.out
:
severe: web application [/nomination##1.0-qa] created threadlocal key of type [java.lang.threadlocal] (value [java.lang.threadlocal@4f43af8f]) , value of type [org.springframework.security.core.context.securitycontextimpl] (value [org.springframework.security.core.context.securitycontextimpl@ffffffff: null authentication]) failed remove when web application stopped. threads going renewed on time try , avoid probable memory leak.
i thought of implementing servletcontextlistener
, close()
context there. however, found contextloaderlistener
implements servletcontextlistener
set in web.xml
:
<listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener>
from javadocs:
**contextdestroyed** public void contextdestroyed(servletcontextevent event) close root web application context. specified by: contextdestroyed in interface servletcontextlistener
so, question why threadlocal not cleanly freed contextloaderlistener.contextdestroyed()
?
we running permgen
errors , while investigating found this. there code similar following in few places:
applicationcontext context = webapplicationcontextutils .getwebapplicationcontext(se.getsession().getservletcontext()); mybeanclass x = context.getbean( "mybean", mybeanclass.class); x.somemethod();
i wonder if above snippet stopping clean shutdown? pointers appreciated.
there many issues hotdeploy should care:
1-deregister database drivers see here.
2-close tasks in multi tasking apps:you may place delay of restart in development mode 1 hour.
3-kill context of spring :you did above pay attention don't import xml form xml .
4-kill cached objects exist in jvm memory :make small object, initializing bean in constructor? change to none constructor keep kill them in method scope! how many method in class calling bean? if many method calls bean don't expect java kill object after come out scope ,jvm keep performance..,so keep class small!.
how code? declare variable out of loops? =null list or object after usage?
5- may increase tomcat start time , stop time.
also see rebel or springboot projects helper .
Comments
Post a Comment