IntrospectorCleanupListener使用

刚发现一个异常:

Exception in thread "sfb_QuartzSchedulerThread" java.lang.OutOfMemoryError: Java heap space
at java.util.TreeMap.key(TreeMap.java:1206)
at java.util.TreeMap.firstKey(TreeMap.java:267)
at java.util.TreeSet.first(TreeSet.java:377)
at org.quartz.simpl.RAMJobStore.acquireNextTrigger(RAMJobStore.java:1209)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:266)

 

看这个信息,就是quartz引起了内存溢出问题。

网上资料都说IntrospectorCleanupListener能解决这种问题,但我的web.xml中是配置了这个监听器的。

网上的资料:

spring 中的提供了一个名为org.springframework.web.util.IntrospectorCleanupListener的监听器。它主 要负责处理由 JavaBeans Introspector的使用而引起的缓冲泄露。spring中对它的描述如下:
 
它是一个在web应用关闭的时候,清除JavaBeans Introspector的监听器.在web.xml中注册这个listener.可以保证在web 应用关闭的时候释放与掉这个web 应用相关的class loader 和由它管理的类
 
如果你使用了JavaBeans Introspector来分析应用中的类,Introspector 缓冲中会保留这些类的引用.结果在你的应用关闭的时候,这些类以及web 应用相关的class loader没有被垃圾回收.
 
不幸的是,清除Introspector的唯一方式是刷新整个缓冲.这是因为我们没法判断哪些是属于你的应用的引用.所以删除被缓冲的 introspection会导致把这台电脑上的所有应用的introspection都删掉.
 
需要注意的是,spring 托管的bean不需要使用这个监听器.因为spring它自己的introspection所使用的缓冲在分析完一个类之后会被马上从javaBeans Introspector缓冲中清除掉.
 
应用程序中的类从来不直接使用JavaBeans Introspector.所以他们一般不会导致内部查看资源泄露.但是一些类库和框架往往会产生这个问题.例如:Struts 和Quartz.
 
单个的内部查看泄漏会导致整个的web应用的类加载器不能进行垃圾回收.在web应用关闭之后,你会看到此应用的所有静态类资源(例如单例). 这个错误当然不是由这个类自身引起的.
 
对于这个解释,有点不明白了,为什么是在web应用关闭的时候才清除。web应用都关闭了,内存还不会释放吗?奇怪。
 
还是看看官方解释吧。

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 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.

 

全文完整版查看

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值