Java – how to use the kill – 3 command to dump the Jave heap every 30 seconds

Please help me, I want to run a shell script, which should use the kill - 3 command to dump the Jave heap every 30 seconds Thank you in advance

Solution

Have you ever tried such a simple shell script?

while true
do
  jmap -dump:file=/tmp/java-`date +%s`.hprof PID_OF_JVM
  sleep 30
done

This will create a file for each snapshot For thread dump, you can use a similar script:

while true
do
  jstack PID_OF_JVM > stack-`date +%s`.txt
  sleep 30
done

I think you can use kill - 3 instead of jstack

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>