OutOfMemoryError java堆空间分析工具 [英] Tools for OutOfMemoryError java heap space analysis

查看:249
本文介绍了OutOfMemoryError java堆空间分析工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到 OutOfMemoryError:Java堆空间

我是否可以使用任何工具来查找根本原因?

Are there any tools I can use to find the root cause ?

推荐答案

您可以使用eclipse mat等分析工具分析应用程序的堆转储,看看消耗了多少堆栈。

You can analyse the heap dump of your application using some analysis tool like eclipse mat to see what's consuming how much of the heap.

但首先需要获取应用程序的堆转储。

But first you need to obtain the heap dump of your application.

要获得当发生OOM错误时,JVM 自动为您生成堆转储,您可以使用 -XX:+ HeapDumpOnOutOfMemoryError 选项。最重要的是,您还可以使用 -XX:HeapDumpPath 选项告诉JVM生成文件的位置。

To have the JVM automatically generate the heap dump for you when the OOM error occurs you can use the -XX:+HeapDumpOnOutOfMemoryError option. On top of that, you can also use the -XX:HeapDumpPath option to tell JVM where to generate the file.

java -XX:HeapDumpPath="D:\heapdumps\YourApp.hprof" -XX:+HeapDumpOnOutOfMemoryError -jar YourApp.jar

生成该文件后,您可以在mat中打开它并进行分析。

Once that file is generated you can open it in mat and do your ananlysis.

您还可以在应用程序运行时随时手动生成堆转储。为此,您可以使用 jdk附带的jmap 命令。

You can also manually generate the heap dump at any point while your application is running. For this purpose you can use the jmap command that comes with jdk.

jmap -dump:live,format=b,file="D:\heapdumps\YourApp.hprof" process_id_of_your_app

您可以使用该工具 - jps ,也附带jdk,可轻松找到应用程序的进程ID。

You can use the tool - jps, which also comes with jdk, to easily find the process id of your application.

jps -m

这篇关于OutOfMemoryError java堆空间分析工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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