Listener that flushes the JDK's JavaBeans Introspector
cache on web app shutdown. Register this listener in your web.xml
to guarantee proper release of the web application class loader and its loaded classes.
If the JavaBeans Introspector has been used to analyzeapplication classes, the system-level Introspector cache will hold ahard reference to those classes. Consequently, those classes and theweb application class loader will not be garbage-collected on web appshutdown! This listener performs proper cleanup, to allow for garbage collection to take effect.
Unfortunately, the only way to clean up the Introspector is to flushthe entire cache, as there is no way to specifically determine theapplication's classes referenced there. This will remove cachedintrospection results for all other applications in the server too.
Note that this listener is not necessary when using Spring'sbeans infrastructure within the application, as Spring's ownintrospection results cache will immediately flush an analyzed classfrom the JavaBeans Introspector cache and only hold a cache within theapplication's own ClassLoader. Although Spring itself does notcreate JDK Introspector leaks, note that this listener shouldnevertheless be used in scenarios where the Spring framework classesthemselves reside in a 'common' ClassLoader (such as the systemClassLoader). In such a scenario, this listener will properly clean up Spring's introspection cache.
Application classes hardly ever need to use the JavaBeansIntrospector directly, so are normally not the cause of Introspectorresource leaks. Rather, many libraries and frameworks do not clean upthe Introspector: e.g. Struts and Quartz.
Note that a single such Introspector leak will cause the entire webapp class loader to not get garbage collected! This has the consequencethat you will see all the application's static class resources (likesingletons) around after web app shutdown, which is not the fault ofthose classes!
This listener should be registered as the first one in web.xml
, before any application listeners such as Spring's ContextLoaderListener. This allows the listener to take full effect at the right time of the lifecycle.
聯(lián)系客服