简体   繁体   English

Java进程出现OutOfMemory错误时如何自动创建堆转储?

[英]How to create Heap Dump automatically when Java process Hits OutOfMemory Error?

I have Java program running in Linux platform and it crash quite often;at this situation, I would like to have heapdump automatically. 我的Java程序在Linux平台上运行,并且经常崩溃;在这种情况下,我希望自动进行heapdump。

Does anyone have script/method to create a Heap Dump Automatically when Java process Hits "OutOfMemory Error" on Linux? Java进程在Linux上命中“ OutOfMemory Error”时,是否有人有脚本/方法自动创建堆转储?

I would appreciate your help. 多谢您的协助。

To take a heap dump automatically, edit {installation directory}/bin/setenv.sh and add this to the JAVA_OPTS: 要自动进行堆转储,请编辑{安装目录} /bin/setenv.sh并将其添加到JAVA_OPTS中:

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=[path to heap dump] -XX:+ HeapDumpOnOutOfMemoryError -XX:HeapDumpPath = [堆转储路径]

Have a look at this page for JVM options, specifically: 请查看此页面上的JVM选项,特别是:

-XX:HeapDumpPath=./java_pid.hprof Path to directory or filename for heap dump. -XX:HeapDumpPath =。/ java_pid.hprof堆转储的目录或文件名的路径。 Manageable. 可管理的。 (Introduced in 1.4.2 update 12, 5.0 update 7.) (在1.4.2更新12、5.0更新7中引入。)

-XX:-HeapDumpOnOutOfMemoryError Dump heap to file when java.lang.OutOfMemoryError is thrown. -XX:-HeapDumpOnOutOfMemoryError当引发java.lang.OutOfMemoryError时,将堆转储到文件中。 Manageable. 可管理的。 (Introduced in 1.4.2 update 12, 5.0 update 7.) (在1.4.2更新12、5.0更新7中引入。)

As stated in the Oracle documentation: Oracle文档中所述:

The -XX:+HeapDumpOnOutOfMemoryError command-line option tells the HotSpot VM to generate a heap dump when an allocation from the Java heap or the permanent generation cannot be satisfied. -XX:+ HeapDumpOnOutOfMemoryError命令行选项告诉HotSpot VM在无法满足Java堆分配或永久生成的情况下生成堆转储。 There is no overhead in running with this option, and so it can be useful for production systems where OutOfMemoryError takes a long time to surface. 使用此选项运行不会产生任何开销,因此对于OutOfMemoryError需要很长时间才能浮出水面的生产系统很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM