读书人

org.springframework.web.util.Intros

发布时间: 2012-10-29 10:03:53 作者: rapoo

org.springframework.web.util.IntrospectorCleanupListener是什么东东

看到好多项目的web.xml中都配置了

<listener>      <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class></listener>

?这个是什么东东呢?

这是Introspector 缓存清除监听器

??????? Spring 提供了一个名为 org.springframework.web.util.IntrospectorCleanupListener的监听器。它主要负责处理由 JavaBean Introspector功能而引起的缓存泄露。IntrospectorCleanupListener 监听器在 Web 应用关闭的时会负责清除 JavaBeanIntrospector 的缓存,在 web.xml 中注册这个监听器可以保证在 Web 应用关闭的时候释放与其相关的 ClassLoader的缓存和类引用。如果您使用了 JavaBean Introspector 分析应用中的类,Introspector缓存会保留这些类的引用,结果在应用关闭的时候,这些类以及Web 应用相关的 ClassLoader 不能被垃圾回收。不幸的是,清除Introspector 的唯一方式是刷新整个缓存,这是因为没法准确判断哪些是属于本 Web 应用的引用对象,哪些是属于其它 Web应用的引用对象。所以删除被缓存的 Introspection 会导致将整个 JVM 所有应用的 Introspection都删掉。需要注意的是,Spring 托管的 Bean 不需要使用这个监听器,因为 Spring 的 Introspection所使用的缓存在分析完一个类之后会马上从 javaBean Introspector 缓存中清除掉,并将缓存保存在应用程序特定的ClassLoader 中,所以它们一般不会导致内存资源泄露。但是一些类库和框架往往会产生这个问题。例如 Struts 和 Quartz 的Introspector 的内存泄漏会导致整个的 Web 应用的 ClassLoader 不能进行垃圾回收。在 Web应用关闭之后,您还会看到此应用的所有静态类引用,这个错误当然不是由这个类自身引起的。解决这个问题的方法很简单,您仅需在 web.xml 中配置IntrospectorCleanupListener 监听器就可以了:

读书人网 >操作系统

热点推荐