Java 使用 -XX:HeapDumpPath 选项但想要集成进程 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24809655/
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
Using -XX:HeapDumpPath option but want to integrate the process id
提问by Nina
When using -XX:+HeapDumpOnOutOfMemoryError
the JVM will not overwrite the heap dump if there is already a dump file under the specified path. I want to be able to have multiple heap dumps in a non-default location, and was planning on using the pid in the heap dump path in order to allow that.
使用-XX:+HeapDumpOnOutOfMemoryError
JVM时,如果指定路径下已经存在转储文件,则不会覆盖堆转储。我希望能够在非默认位置进行多个堆转储,并计划在堆转储路径中使用 pid 以允许这样做。
However, when I tried to specify the argument like so:
但是,当我尝试像这样指定参数时:
-XX:HeapDumpPath=some/heapdump/path/heapdump-%p.hprof
And then created a heap dump, I got %p
and not the actual pid in the file name. However, the use of %p
seems to work with the -XX:OnOutOfMemoryError
option. Is there some other syntax that I'm supposed to use for -XX:HeapDumpPath=
?
然后创建了一个堆转储,我得到了%p
而不是文件名中的实际 pid。但是,使用%p
似乎可以与该-XX:OnOutOfMemoryError
选项一起使用。还有其他一些我应该使用的语法-XX:HeapDumpPath=
吗?
回答by Brett Okken
That can be a path to a file OR directory. If you have a path to a directory, the generated file name will have pid in it by default.
这可以是文件或目录的路径。如果您有目录的路径,则默认情况下生成的文件名中将包含 pid。
http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
回答by mcoolive
You should add which Java you use. These options depends on the JVM vendor (IBM, Oracle, etc.)
您应该添加您使用的 Java。这些选项取决于 JVM 供应商(IBM、Oracle 等)
OnOutOfMemoryErrorsays WHEN to perform the dump. HeapDumpPathsays WHERE to put the dump. I think the use of HeapDumpPath turns on the first, but I advice to use both for clarity.
OnOutOfMemoryError表示何时执行转储。HeapDumpPath说明放置转储的位置。我认为首先使用 HeapDumpPath,但为了清楚起见,我建议同时使用两者。
About the original question, use the pid in the dump file name is a good practice. It can help in particular to corolate and analyse what happens after multiple issues/restarts.
关于原始问题,在转储文件名中使用 pid 是一个好习惯。它特别有助于关联和分析多个问题/重启后发生的情况。
The exact syntax is explained here.