最近的一次系统测试部署后,我们的一个 servlet 受到的打击比平时严重得多,我们注意到内存开始攀升,weblogic 最终会死掉。
我非常自豪的是,我的实习生发现了内存泄漏的根源。
每当收到请求时,都会调用此行:
JAXBContext jc = JAXBContext.newInstance(“ruby.oracle_servlet.schemas”);
由于某种原因,该对象永远不会被垃圾收集。
一旦我们将其设为静态并移动到初始化它的位置,内存泄漏就消失了。
我们的另一位开发人员将该行放入独立 java 应用程序的 while 循环中,也看到内存不断增加。
有谁知道为什么该对象没有被垃圾收集?
谢谢
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.
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?
Thanks
发布评论
评论(2)
哪个实施&您使用的 JAXB 版本?如果您使用 Java SE 6 附带的参考实现,那么它就是 Metro (https://jaxb. dev.java.net/)。
以下是一些与内存相关的错误:
如果您碰巧使用 MOXy 实现 (http://www.eclipse.org/ eclipselink/moxy.php) 然后我可以帮助调试。
好消息是 JAXBContext 是线程安全的,并且只能创建一次并重复使用。重用 JAXBContext 似乎也可以解决内存泄漏问题。
有关详细信息,请参阅:
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:
If you happen to be using the MOXy implementation (http://www.eclipse.org/eclipselink/moxy.php) then I can help debug.
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:
是的,这是泄漏。每次调用此方法时,它将加载类“ruby.oracle_servlet.schemas”。
Yes, it's a leak. It will load the class “ruby.oracle_servlet.schemas”, every time this method is called.