类 IntrospectorCleanupListener
- java.lang.Object
- org.springframework.web.util.IntrospectorCleanupListener
- 所有已实现的接口:
EventListener
,ServletContextListener
public class IntrospectorCleanupListener extends Object implements ServletContextListener
Listener that flushes the JDK'sJavaBeans Introspector
cache on web app shutdown. Register this listener in yourweb.xml
to guarantee proper release of the web application class loader and its loaded classes.If the JavaBeans Introspector has been used to analyze application classes, the system-level Introspector cache will hold a hard reference to those classes. Consequently, those classes and the web application class loader will not be garbage-collected on web app shutdown! This listener performs proper cleanup, to allow for garbage collection to take effect.
Unfortunately, the only way to clean up the Introspector is to flush the entire cache, as there is no way to specifically determine the application's classes referenced there. This will remove cached introspection results for all other applications in the server too.
Note that this listener is not necessary when using Spring's beans infrastructure within the application, as Spring's own introspection results cache will immediately flush an analyzed class from the JavaBeans Introspector cache and only hold a cache within the application's own ClassLoader. Although Spring itself does not create JDK Introspector leaks, note that this listener should nevertheless be used in scenarios where the Spring framework classes themselves reside in a 'common' ClassLoader (such as the system ClassLoader). In such a scenario, this listener will properly clean up Spring's introspection cache.
Application classes hardly ever need to use the JavaBeans Introspector directly, so are normally not the cause of Introspector resource leaks. Rather, many libraries and frameworks do not clean up the Introspector: e.g. Struts and Quartz.
Note that a single such Introspector leak will cause the entire web app class loader to not get garbage collected! This has the consequence that you will see all the application's static class resources (like singletons) around after web app shutdown, which is not the fault of those 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.
构造器概要
构造器 构造器 说明 IntrospectorCleanupListener()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
contextDestroyed(ServletContextEvent event)
void
contextInitialized(ServletContextEvent event)
构造器详细资料
IntrospectorCleanupListener
public IntrospectorCleanupListener()
方法详细资料
contextInitialized
public void contextInitialized(ServletContextEvent event)
- 指定者:
contextInitialized
在接口中ServletContextListener
contextDestroyed
public void contextDestroyed(ServletContextEvent event)
- 指定者:
contextDestroyed
在接口中ServletContextListener