使用 jconsole 时 Java 转储堆文件的位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2726182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 12:10:14  来源:igfitidea点击:

Location of Java dump heap file when using jconsole?

javaeclipsejconsoleheap-dump

提问by Jim Ferrans

Well this is embarrassing ...

嗯,这很尴尬……

I'm starting to play with the Eclipse Memory Analyzer to look for Java memory leaks on a Windows box. Step 1 is to obtain a heap dump file. To do this I start my Java (javaw.exe) process from within Eclipse and connect to it with jconsole. Then on the jconsole MBeans tab I click the dumpHeap button. The first time I did this, I saw a pop-up saying it had created the heap dump file, but not giving its name or location. Now whenever I do a dumpHeap again while connected to a different javaw.exe process, jconsole says:

我开始使用 Eclipse 内存分析器来查找 Windows 机器上的 Java 内存泄漏。第 1 步是获取堆转储文件。为此,我从 Eclipse 中启动我的 Java (javaw.exe) 进程并使用 jconsole 连接到它。然后在 jconsole MBeans 选项卡上单击 dumpHeap 按钮。我第一次这样做时,我看到一个弹出窗口,说它创建了堆转储文件,但没有提供它的名称或位置。现在,每当我在连接到不同的 javaw.exe 进程时再次执行 dumpHeap 时,jconsole 都会说:

Problem invoking dumpHeap : java.io.IOException: File exists

and of course doesn't give its name or path. Where could it be?

当然没有给出它的名字或路径。它可能在哪里?

I've searched my C: drive (using cygwin command line tools) for files containing "hprof" or "java_pid" or "heapdump" and didn't find anything plausible. I've even used the Windows search to look for all files in my Eclipse workspace that have changed in the last day.

我已经在我的 C: 驱动器(使用 cygwin 命令行工具)中搜索了包含“hprof”或“java_pid”或“heapdump”的文件,但没有找到任何合理的东西。我什至使用 Windows 搜索来查找我的 Eclipse 工作区中在最后一天发生更改的所有文件。

I'm using the Sun Java 1.6 JVM, and don't have -XX:HeapDumpPath set.

我使用的是 Sun Java 1.6 JVM,并且没有设置 -XX:HeapDumpPath。

Update (28 April 2010):My original heap file location must have been determined by jconsole, the tool I triggered the heap dump from. The JVM's heap dump location must apply only to heap dumps it triggers (eg, on an OutOfMemoryException).

更新(2010 年 4 月 28 日):我的原始堆文件位置必须由 jconsole 确定,这是我从中触发堆转储的工具。JVM 的堆转储位置必须仅适用于它触发的堆转储(例如,在 OutOfMemoryException 上)。

Matt B's suggestion to use jvisualvm nicely solves my problem by pointing me to a far more useful replacement for the old jconsole. It has a nice memory profiler that shows which types of objects are most numerous and hold the most memory. And it has a monitor that shows actual memory use over time. When you ask it for a heap dump, it tells you the file name even! The Eclipse Memory Analyzer gives you full details.

Matt B 使用 jvisualvm 的建议很好地解决了我的问题,它为我指出了一个更有用的旧 jconsole 替代品。它有一个很好的内存分析器,可以显示哪些类型的对象数量最多,内存最多。它有一个监视器,可以显示一段时间内的实际内存使用情况。当您要求它进行堆转储时,它甚至会告诉您文件名!Eclipse Memory Analyzer 为您提供完整的细节。

采纳答案by matt b

Try jvisualvm, it has a much better interface.

试试jvisualvm,它有一个更好的界面。

Note that starting with JDK version 6 update 7 or greater, Java VisualVM is bundled with JDK. See here.

请注意,从 JDK 版本 6 更新 7 或更高版本开始,Java VisualVM 与 JDK 捆绑在一起。见这里

回答by Chris Dennett

You could always use ProcessMonitorto see where it's trying to write to :) Done this myself in the past.

您可以随时使用ProcessMonitor来查看它尝试写入的位置:) 过去我自己做过。

回答by Jason Jenkins

According to the docsfor the Sun Java SE6 JVM:

根据Sun Java SE6 JVM的文档

By default the heap dump is created in a file called java_pid<pid>.hprof in the working directory of the VM

默认情况下,堆转储是在VM 工作目录中名为 java_pid< pid>.hprof的文件中创建的

In Eclipse, the working directory is defined on the "Arguments" tab of the "Run Configurations" dialog. The default value is the same directory as the class that you are running.

在 Eclipse 中,工作目录在“运行配置”对话框的“参数”选项卡上定义。默认值是与您正在运行的类相同的目录。

回答by tsimgsong

why don't you set the first parameter for dumpHeap(String,boolean) when you try to invoke dumpHeap() from jconsole? it's the generated heapdump file's location and filename.

当您尝试从 jconsole 调用 dumpHeap() 时,为什么不为 dumpHeap(String,boolean) 设置第一个参数?它是生成的 heapdump 文件的位置和文件名。

回答by Francesco

I found the dumped file into the same folder where the .bat file whic launch my java application is placed. (I'm using windows 8.1, java 7) In my case jboss, /jboss-as/bin/ folder. To find it I searched * files, with today creation date and more than 200MB.

我发现转储的文件位于启动我的 java 应用程序的 .bat 文件所在的同一文件夹中。(我使用的是 windows 8.1,java 7)在我的情况下是 jboss,/jboss-as/bin/ 文件夹。为了找到它,我搜索了 * 文件,今天的创建日期超过 200MB。