Java堆转储&关闭 - 什么命令? [英] Java heap dump & shut down - what order?
问题描述
我想检测 OutOfMemoryError
,进行堆转储,并自动退出Java程序。假设我的JVM有以下命令行参数:
I would like to detect an OutOfMemoryError
, take a heap dump, and automatically exit the Java program. Say I have the following command-line arguments for my JVM:
-XX:OnOutOfMemoryError="kill -9 %p"
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/tmp
首先发生什么?进程是否转储内存然后退出,或者反过来?
Which happens first? Does the process dump memory and then quit, or the other way around?
推荐答案
我宁愿依赖于调用脚本更确定地处理订购,即
I would rather rely on calling into a script that handles the ordering more deterministically i.e.
-XX:OnOutOfMemoryError="/<SomeStandardLocation>/heapAndQuit.sh"
heapAndQuit.sh然后将使用一种方法来查找 pid
当前的过程。
识别pid的一种简单方法是使用您的进程写入的日志文件位置
heapAndQuit.sh will then employ a method to find the pid
of the current process.
One simple way to identify the pid is to use the log file location your process is writing to
lsof | grep /var/tmp/<yourlogfileName> | cut -d " " -f1 | uniq
然后我将使用 jmap
转储并且 kill -9
随后
I will then use jmap
to dump and kill -9
subsequently
这篇关于Java堆转储&关闭 - 什么命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!