java - setContextClassLoader implications -
i'm trying clean tomcat warnings memory leaks due creating own threads. http://wiki.apache.org/tomcat/memoryleakprotection proposes call mythread.setcontextclassloader(null) prior starting thread.
what implication of call? code in run() method still able resolve classes application?
yes will. thread.getcontextclassloader() mechanism generic frameworks load resources further down class loader tree.
take tomcat's class loader hierarchy.
bootstrap | system | common / \ webapp1 webapp2 ... the servlet or jsp framework resides in common class loader. if 1 of these frameworks load classpath resource webapp1, try:
getclass().getresource("/some/resource/in/webapp1"); // fail but since class loading mechanics delegates calls class loader chain, fail. means frameworks needs load resource instead do:
thread.currentthread().getcontextclassloader().getresource("/some/resource/in/webapp1"); and servlet container makes sure webapp1 class loader whenever thread executing in context. thread's context classloader way frameworks load classes "the wrong direction".
when spawn new thread, thread gets, default context class loader of parent (your webapp1 classloader). if consequently stop webapp1, tomcat supposed able gc webapp, unable long there's reference left webapp1 class loader - hence warning.
Comments
Post a Comment