论坛首页 Java企业应用论坛

Struts+Spring+Hibernate内存泄漏查找与处理

浏览 60034 次
该帖已经被评为精华帖
作者 正文
   发表时间:2007-01-02  
Readonly 写道
yueguangyuan 写道
spring中的提供了一个名为org.springframework.web.util.IntrospectorCleanupListener的监听器。它主要负责处理由 
JavaBeans  Introspector的使用而引起的缓冲泄露。spring中对它的描述如下:

它是一个在web应用关闭的时候,清除JavaBeans Introspector的监听器.在web.xml中注册这个listener.可以保证在web 应用关闭的时候释放与掉这个web 应用相关的class loader 和由它管理的类


yueguangyuan 写道
已经很明显了,没有用Lisener的服务器的内存用量明显呈上升趋势


说不通地啊,假设是这个Listener起作用的话,说明你的servlet context在测试的24小时内被关闭了N次,只有这样才能触发contextDestroyed事件,肯定是你的某段代码有问题才会导致web应用反复自动重启。


我想你说的有道理,看来我只是从表面上去理解了问题,并不知道实际是怎样操作的。但是现在是在放假时间,我没法模拟这个环境,要等到上班我需要好好跟踪一个IntrospectorCleanupListener的contextDestroyed是什么时候运行的。

刚才去看了一下IntrospectorCleanupListener的代码,发现的确不是我当初想象的样子:

/**
 * Listener that flushes the JavaBeans Introspector cache on web app shutdown.
 * Register this listener in your web.xml to guarantee proper release of
 * the web app class loader and the classes that it holds.
 *
 * <p>If the JavaBeans Introspector has been used to analyze application classes,
 * the Introspector cache will hold a hard reference to those classes.
 * Consequently, those classes and the web app class loader will not be
 * garbage collected on web app shutdown!
 *
 * <p>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.
 *
 * <p>Note that this listener is <i>not</i> necessary when using Spring's
 * beans infrastructure, as Spring's own introspection results cache will
 * immediately flush an analyzed class from the JavaBeans Introspector cache.
 *
 * <p>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,
 * for example Struts and Quartz.
 *
 * <p>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!
 *
 * @author Juergen Hoeller
 * @since 1.1
 * @see java.beans.Introspector#flushCaches
 */
public class IntrospectorCleanupListener implements ServletContextListener {

	public void contextInitialized(ServletContextEvent event) {
	}

	public void contextDestroyed(ServletContextEvent event) {
		Introspector.flushCaches();
	}

}


Listener that flushes the JavaBeans Introspector cache on web app shutdown.
Register this listener in your web.xml to guarantee proper release of
the web app class loader and the classes that it holds.

但是我的确是没有修改任何东西而仅仅是增加了这个Listener的注册,难道是障眼法?最近3个月客户也没再像我们提出服务器崩溃的问题,迷糊了。

顺便提一下:我后来在做另一个项目的时候,用JProfiler监视,如果服务器上跑SNMP的计划任务,那么JProfiler跑不过1个小时,就会报错停掉(实际运行时没有这个问题),错误具体信息我忘掉了,是说JRE版本冲突,很奇怪的说,难道说是JProfiler会收本地程序运行的影响?
0 请登录后投票
   发表时间:2007-01-02  
jprofiler本质上是通过调用jni来实现性能监控的。
0 请登录后投票
   发表时间:2007-01-04  
结果装上我的东西跑了两个月就崩了?

没有看到具体崩的描述,崩有好多种情况:OOM、连接过多、打开文件数过多(打开未关闭)、死锁等等情况。

可以通过做ThreadDump来进行详细分析到当时的情况,比如哪些线程还在干活,死锁等等什么的?
0 请登录后投票
   发表时间:2007-01-14  
楼主做过的也是我将要做的,ssh框架我们一直在用,对于OpenSessionInViewFilter没有发现有此问题,还不知道quartz可能会造成这么大的风险,还真得注意了
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics