JAXBContext.newInstance内存泄漏 [英] JAXBContext.newInstance memory leak

查看:993
本文介绍了JAXBContext.newInstance内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近在系统测试中部署之后,我们的一个servlet比平时受到了更大的打击,我们注意到内存开始攀升,weblogic最终会死亡。
我的实习生,我非常自豪,发现了内存泄漏的来源。

After a recent deployment in system test, one of our servlets was getting hit much harder than usual and we noticed memory started climbing and weblogic would eventually die. My intern, I was very proud, discovered the source of the memory leak.

每当有请求进来时,都会调用此行:

Whenever a request comes in, this line gets called:

JAXBContext jc = JAXBContext.newInstance("ruby.oracle_servlet.schemas");

由于某种原因,对象永远不会被垃圾收集。
一旦我们将它设置为静态并移动到我们初始化它的地方,我们的内存泄漏便消失了。

For some reason, the object never gets garbage collected. Once we made it static and moved where we initialized it, our memory leak went away.

我们的另一个开发人员将这一行放在while循环中在独立的Java应用程序中,也看到了内存蠕变。

Another one of our developers put just that line in a while loop in standalone java application and also saw the memory creep up and up.

有没有人有任何想法为什么该对象不会被垃圾收集?

Does anyone have any ideas why that object doesn't get garbage collected?

谢谢

推荐答案

哪种实施&您使用的JAXB版本?如果您使用的是Java SE 6附带的参考实现,那么它就是Metro( https://jaxb.dev .java.net / )。

Which implementation & version of JAXB are you using? If you are using the reference implementation that comes with Java SE 6, then it is Metro (https://jaxb.dev.java.net/).

以下是一些与内存相关的错误:

Here are some of there memory related bugs:

  • https://jaxb.dev.java.net/issues/buglist.cgi?Submit+query=Submit+query&component=jaxb&email1=&emailtype1=exact&emailassigned_to1=1&email2=&emailtype2=exact&emailreporter2=1&issueidtype=include&issue_id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&short_desc=memory&short_desc_type=fulltext&long_desc=&long_desc_type=fulltext&issue_file_loc=&issue_file_loc_type=fulltext&status_whiteboard=&status_whiteboard_type=fulltext&keywords=&keywords_type=anytokens&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&order=Reuse+same+sort+as+last+time

如果您正好使用MOXy实现( http://www.eclipse.org/eclipselink/moxy.php )然后我可以帮忙调试。

If you happen to be using the MOXy implementation (http://www.eclipse.org/eclipselink/moxy.php) then I can help debug.

好消息是JAXBContext是线程安全的,只能创建一次并重新使用。重用JAXBContext似乎也解决了你的内存泄漏问题。

The good news is that JAXBContext is thread-safe and should only be created once and re-used. Reusing the JAXBContext also appears to be solving your memory leak.

有关详细信息,请参阅:

For more information see:

  • http://jaxb.java.net/guide/Performance_and_thread_safety.html

这篇关于JAXBContext.newInstance内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆