On Jul 22, 2010, at 12:16 AM, jdiaz wrote: > > I have detected that when I move my jar with the web application that > contains the singleton and the rest of the classes used from my webapp > classloader to the shared loader ( > http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html#Overview > here you can see tomcat 5.5 classloaders), it works ok. > > I think this is a bit strange, because when I have my classes in the webapp > classloader, openejb loads ok the singleton, and executes the @Postconstruct > method, so in my opinion it seems before predestroy is done something that > should be done after @Predestroy in order to have the same behaviour in this > operation as in postconstruct.
I tracked down the code in Tomcat which does the aggressive nulling of your variable: http://svn.apache.org/repos/asf/tomcat/tc5.5.x/tags/TOMCAT_5_5_24/container/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java http://svn.apache.org/repos/asf/tomcat/tc6.0.x/tags/TOMCAT_6_0_3/java/org/apache/catalina/loader/WebappClassLoader.java In either of the links above see the code comment "// Null out any static or final fields from loaded classes," That would explain why moving the class to the Tomcat lib directory "fixes" the problem as then Tomcat will not have it listed in the WepAppClassLoader and will not modify your variables. It seems as of versions 5.5.24 and 6.0.3, they added this system property which you can use to shut off the stripping of static/final variables: -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -David
