Java heap dump & shut down - what order?

前端 未结 5 1339
暖寄归人
暖寄归人 2021-02-07 08:35

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:

5条回答
  •  无人共我
    2021-02-07 09:01

    I would rather rely on calling into a script that handles the ordering more deterministically i.e.

    -XX:OnOutOfMemoryError="//heapAndQuit.sh"
    

    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/ | cut -d " " -f1 | uniq
    

    I will then use jmap to dump and kill -9 subsequently

提交回复
热议问题