设为首页 收藏本站
查看: 1394|回复: 0

[经验分享] apache standard.jar 包 c:forEach标签是否存在着内存泄露?

[复制链接]

尚未签到

发表于 2017-1-14 09:21:43 | 显示全部楼层 |阅读模式
近来公司的服务器内存占用很大,运行一段时间,gc就占用cpu 100%,然后tomcat拒绝访问。
本地调试了几天,代码实在看不出问题。网上搜索了大量的文章研读,必须江南白衣,和javaeye上关于gc的文章,对服务器进行调试,还是没用。
服务器上才gc日志如下:

210.970: [CMS-concurrent-mark-start]
211.266: [CMS-concurrent-mark: 0.211/0.295 secs] [Times: user=0.49 sys=0.00, real=0.29 secs]
211.266: [CMS-concurrent-preclean-start]
211.270: [CMS-concurrent-preclean: 0.004/0.004 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
211.270: [CMS-concurrent-abortable-preclean-start]
215.141: [CMS-concurrent-abortable-preclean: 1.351/3.871 secs] [Times: user=2.64 sys=0.11, real=3.87 secs]
215.142: [GC[YG occupancy: 132189 K (235968 K)]
215.142: [Rescan (parallel) , 0.0644930 secs]
215.207: [weak refs processing, 0.1014540 secs] [1 CMS-remark: 135253K(262144K)] 267442K(498112K), 0.1661810 secs] [Times: user=0.30 sys=0.00, real=0.16 secs]
215.308: [CMS-concurrent-sweep-start]
215.419: [CMS-concurrent-sweep: 0.108/0.111 secs] [Times: user=0.14 sys=0.02, real=0.11 secs]
215.419: [CMS-concurrent-reset-start]
215.448: [CMS-concurrent-reset: 0.029/0.029 secs] [Times: user=0.04 sys=0.02, real=0.03 secs]


无奈,用jprofiler调试,过滤程序中所有使用过的pojo,发现凡是jsp用了 <c:forEach...这个标签的,每刷新一次,所用的model类的实例就会增加,在jprofiler中手工点击垃圾回收按钮后,回收不了。但是其他的地方,都可以回收。
通过jprofiler追踪引用,最好追踪到对应的jsp的编译后的文件,下面是部分代码

private boolean _jspx_meth_c_005fforEach_005f2(PageContext _jspx_page_context)
throws Throwable {
PageContext pageContext = _jspx_page_context;
JspWriter out = _jspx_page_context.getOut();
//  c:forEach
org.apache.taglibs.standard.tag.rt.core.ForEachTag _jspx_th_c_005fforEach_005f2 = (org.apache.taglibs.standard.tag.rt.core.ForEachTag) _005fjspx_005ftagPool_005fc_005fforEach_0026_005fvar_005fitems.get(org.apache.taglibs.standard.tag.rt.core.ForEachTag.class);
_jspx_th_c_005fforEach_005f2.setPageContext(_jspx_page_context);
_jspx_th_c_005fforEach_005f2.setParent(null);
// /html/study/setMustCourse/orgListCourse.jsp(22,3) name = var type = java.lang.String reqTime = false required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
_jspx_th_c_005fforEach_005f2.setVar("orgCourse");
// /html/study/setMustCourse/orgListCourse.jsp(22,3) name = items type = java.lang.Object reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
_jspx_th_c_005fforEach_005f2.setItems((java.lang.Object) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${courseInfoList}", java.lang.Object.class, (PageContext)_jspx_page_context, null, false));
//在这里把request中courseInfoList赋值给_jspx_th_c_005fforEach_005f2的item属性。
int[] _jspx_push_body_count_c_005fforEach_005f2 = new int[] { 0 };
try {
int _jspx_eval_c_005fforEach_005f2 = _jspx_th_c_005fforEach_005f2.doStartTag();
if (_jspx_eval_c_005fforEach_005f2 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
do {
out.write("\r\n");
out.write("\t\t\t\t<option style=\"color:blue\" value='");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${orgCourse.courseId}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
out.write("' title=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${orgCourse.courseTitle}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
out.write('"');
out.write('>');
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${orgCourse.courseCode}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
out.write("&nbsp;&nbsp;");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${orgCourse.courseTitle}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
out.write(" </option>\r\n");
out.write("\t\t\t");
int evalDoAfterBody = _jspx_th_c_005fforEach_005f2.doAfterBody();
if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
break;
} while (true);
}
if (_jspx_th_c_005fforEach_005f2.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
return true;
}
} catch (Throwable _jspx_exception) {
while (_jspx_push_body_count_c_005fforEach_005f2[0]-- > 0)
out = _jspx_page_context.popBody();
_jspx_th_c_005fforEach_005f2.doCatch(_jspx_exception);
} finally {
_jspx_th_c_005fforEach_005f2.doFinally(); //在这里进行属性的清除
_005fjspx_005ftagPool_005fc_005fforEach_0026_005fvar_005fitems.reuse(_jspx_th_c_005fforEach_005f2);
}
return false;
}


无奈,下载apache standard的源代码,发现javax.servlet.jsp.jstl.core.LoopTagSupport类中代码如下:

public void doFinally() {
/*
* Make sure to un-expose variables, restoring them to their
* prior values, if applicable.
*/
unExposeVariables();
}
}


没有对item属性清除。
于是hack子类 ForEachSupport的代码,增加了一个方法

public void doFinally() {
super.doFinally();
items = null;
rawItems = null;
}


然后用jprofiler进行测试,发现可以回收了。
存在的疑问如下:
1. ForEachSupport类,本身有个realease方法,貌似一直没有执行

public void release() {
super.release();
items = null;
rawItems = null;
}


2. c:forEach标签真的存在内存泄露问题?
3. java gc时的触发点是什么?在什么情况下会出现“CMS-concurrent-abortable-preclean-start]”这个问题?
4. 下面那几句话具体什么意思?

215.308: [CMS-concurrent-sweep-start]
215.419: [CMS-concurrent-sweep: 0.108/0.111 secs] [Times: user=0.14 sys=0.02, real=0.11 secs]
215.419: [CMS-concurrent-reset-start]
215.448: [CMS-concurrent-reset: 0.029/0.029 secs] [Times: user=0.04 sys=0.02, real=0.03 secs]


5. 如果程序不存在内存泄露的情况,在服务器运行一段时间之后,如果进行full gc,服务器占用内存是不是应该等于服务器刚刚重启后占用的内存?
( tomcat 6, spring+struts+hibernate,没有使用2级缓存,没有使用lazy加载,采用的是appfuse1.9的架构)

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-328173-1-1.html 上篇帖子: :[org.apache.ibatis.io.ResolverUtil]Could not read package: com.ossext.system.do 下篇帖子: 第12章 使用 Apache Wicket写你的持久化层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表