简体   繁体   English

奇怪的内存异常

[英]Strange Out of Memory Exception

We are seeing a very weird situation with our web app. 我们的网络应用程序看到了一个非常奇怪的情况。 It uses Tomcat 6 and the web service is implemented with Jersey. 它使用Tomcat 6,并且使用Jersey实现Web服务。 The service calls below are meant to return JSON data. 下面的服务调用旨在返回JSON数据。

The following throws OOM exception: 以下抛出OOM异常:

http://mywebservices/get/some/data/for/1
http://mywebservices/get/some/more/data/for/12345
http://mywebservices/get/some/other/data/for/abc

But, the following works fine: 但是,以下工作正常:

http://mywebservices/get/some/data/for/12345
http://mywebservices/get/some/more/data/for/1

These are just made up calls to show what is happening. 这些只是打电话来显示正在发生的事情。 We have real time monitoring services that show ~5 GB available memory for JVM. 我们有实时监控服务,为JVM显示约5 GB的可用内存。 We believe the OOM the Tomcat is throwing at us is a fake/incorrect response. 我们相信Tomcat向我们投掷的OOM是假的/不正确的回应。 The funny thing is even for completely different web services, the stack trace shown on the browser remains the same. 有趣的是,即使对于完全不同的Web服务,浏览器上显示的堆栈跟踪也保持不变。 We are very sure we are seeing the trace that is totally irrelevant given the web service request. 鉴于Web服务请求,我们非常确定我们看到的跟踪完全不相关。 So we are figuring out if we actually have a leak. 所以我们弄清楚我们是否真的有泄漏。

Meantime, it would be great to know if anybody has encountered this before. 同时,知道是否有人之前遇到过这个问题会很棒。

Thanks. 谢谢。

Ok, so we believe we have found the root cause for this issue. 好的,我们相信我们找到了这个问题的根本原因。 There was a leak indeed because of the usage of ObjectOutputStream and ObjectInputStream. 由于使用了ObjectOutputStream和ObjectInputStream,确实存在泄漏。

Now ObjectOutputStream has a reset() method that can clear the references but there is nothing like that for the ObjectInputStream. 现在,ObjectOutputStream有一个reset()方法可以清除引用,但ObjectInputStream没有类似的东西。

This link helped us: Java out of heap space during serialization 这个链接帮助我们: Java在序列化期间没有堆空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM