0

Let say my java application is running with some pid number, I have written the program to get my application pid runtime, now how to collect the heap dump for this pid from my java program. I followed the below link but it will give heap dump for all live objects not specific my pid, Is there a way to collect heap dump for only specific to my pid. Assume I have pid number.

https://blogs.oracle.com/sundararajan/programmatically-dumping-heap-from-java-applications

intu
  • 39
  • 6

1 Answers1

-1

It seems to be as simple as:

jmap -dump:format=b,file=<file-path> <pid> 

This comes from the top of an article I found that offers other ways of dumping the heap as well:

https://dzone.com/articles/how-to-capture-java-heap-dumps-7-options

If you need to do this inside of your Java code, just call this tool via the subprocess module. The above article provides some alternatives.

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
  • Thanks for the response. This jmap depends on JDK but I want to generate with jre dependent only. – intu May 16 '19 at 06:50
  • Hi intu, posted the code on the link - https://stackoverflow.com/questions/407612/how-to-get-a-thread-and-heap-dump-of-a-java-process-on-windows-thats-not-runnin/56163317#56163317 – Ramesh Subramanian May 16 '19 at 07:41
  • Hi Ramesh, nowhere you using pid to generate JMXServiceURL only checking the pid > 0..how this pid is attach to collect heap – intu May 16 '19 at 16:06