如何调试Java OutOfMemory异常? [英] How to debug Java OutOfMemory exceptions?

查看:148
本文介绍了如何调试Java OutOfMemory异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试 java.lang.OutOfMemoryError 例外的最佳方法是什么?

What is the best way to debug java.lang.OutOfMemoryError exceptions?

当我们发生这种情况时应用程序,我们的应用服务器(Weblogic)生成堆转储文件。我们应该使用堆转储文件吗?我们应该生成Java线程转储吗?究竟有什么区别?

When this happens to our application, our app server (Weblogic) generates a heap dump file. Should we use the heap dump file? Should we generate a Java thread dump? What exactly is the difference?

更新:生成线程转储的最佳方法是什么? kill -3 (我们的应用程序在Solaris上运行)是杀死应用程序并生成线程转储的最佳方法吗?有没有办法生成线程转储但不杀死应用程序?

Update: What is the best way to generate thread dumps? Is kill -3 (our app runs on Solaris) the best way to kill the app and generate a thread dump? Is there a way to generate the thread dump but not kill the app?

推荐答案

我使用 Eclipse Memory Analyzer(MAT) Java Visual VM 来分析堆转储。 MAT提供了一些可以运行的报告,可以让您大致了解在代码中将工作重点放在哪里。 VisualVM有一个更好的界面(在我看来)实际检查你有兴趣检查的各种对象的内容。它有一个过滤器,您可以在其中显示特定类的所有实例,并查看它们的引用位置以及它们自己引用的内容。已经有一段时间了,因为我使用了这两种工具,现在它们可能有更接近的功能集。当时使用两者对我来说都很好。

I've had success using a combination of Eclipse Memory Analyzer (MAT) and Java Visual VM to analyze heap dumps. MAT has some reports that you can run that give you a general idea of where to focus your efforts within your code. VisualVM has a better interface (in my opinion) for actually inspecting the contents of the various objects that you are interested in examining. It has a filter where you can have it display all instances of a particular class and see where they are referenced and what they reference themselves. It has been a while since I've used either tool for this they may have a closer feature set now. At the time using both worked well for me.

这篇关于如何调试Java OutOfMemory异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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