Java 是否可以指定 JVM 崩溃转储的去向?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1880166/
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-12 23:29:22  来源:igfitidea点击:

Is it possible to specify where JVM's crash dumps go?

jvmloggingjavacrash-dumps

提问by Joonas Pulakka

We have a desktop application using JNI that occasionally causes the JVM to crash. Luckily the JVM produces a hs_err_pidXXXX.logfile, which is quite useful in debugging such errors. However, it always seems to go to the current working directory, and it's annoying to dig it from there, since our other log files all go to a specific "log file place".

我们有一个使用 JNI 的桌面应用程序,它偶尔会导致 JVM 崩溃。幸运的是,JVM 生成了一个hs_err_pidXXXX.log文件,这在调试此类错误时非常有用。但是,它似乎总是转到当前工作目录,从那里挖掘它很烦人,因为我们的其他日志文件都转到特定的“日志文件位置”。

Is it possible to specify different location for those "crash dump" files? How?

是否可以为这些“崩溃转储”文件指定不同的位置?如何?

采纳答案by Andrew Carr

Joonas,

乔纳斯,

Although the HeapDumpPath works for the heap dump it is not the answer for your question. The heap dump and the jvm crash log are two separate things.

尽管 HeapDumpPath 适用于堆转储,但它不是您问题的答案。堆转储和 jvm 崩溃日志是两个独立的东西。

To change the destination of the jvm crash log run java with this option:

要更改 jvm 崩溃日志的目标,请使用此选项运行 java:

-XX:ErrorFile=/path/to/file.

Path/to/file is the place you want the JVM crash log to output.

Path/to/file 是您希望 JVM 崩溃日志输出的位置。

回答by Schildmeijer

By default the heap dump is created in a file called java_pidpid.hprofin the working directory of the VM. You can specify an alternative file name or directory with the -XX:HeapDumpPath=option. For example -XX:HeapDumpPath=/disk2/dumpswill cause the heap dump to be generated in the /disk2/dumpsdirectory.

默认情况下,堆转储是在VM 工作目录中名为java_pidpid.hprof的文件中创建的。您可以使用-XX:HeapDumpPath=选项指定备用文件名或目录。例如-XX:HeapDumpPath=/disk2/dumps将导致在/disk2/dumps目录中生成堆转储