How to get a thread and heap dump of a Java process on Windows that's not running in a console
To get a thread and heap dump of a Java process on Windows that is not running in a console, you can use the jstack
and jmap
tools that are included with the Java Development Kit (JDK).
To get a thread dump of a Java process, you can use the jstack
tool. The jstack
tool prints the stack traces of all threads that are running in the Java process, along with the status of each thread.
To use jstack
, you will need to know the process ID (PID) of the Java process. You can use the Task Manager
on Windows to find the PID of the process.
To get a thread dump of a Java process with PID 12345, you can use the following command:
jstack 12345
This will print the stack traces of all threads in the Java process with PID 12345 to the console.
To save the thread dump to a file, you can redirect the output to a file using the >
operator.
For example:
jstack 12345 > threaddump.txt
This will save the thread dump to the file threaddump.txt
.
To get a heap dump of a Java process, you can use the jmap
tool. The jmap
tool creates a snapshot of the heap memory of the Java process, which can be used to analyze memory usage and identify memory leaks.
To use jmap
, you will again need the PID of the Java process.
To get a heap dump of a Java process with PID 12345, you can use the following command:
jmap -dump:format=b,file=heapdump.bin 12345
This will create a binary heap dump file called heapdump.bin
for the Java process with PID 12345.
You can then use a heap dump analysis tool, such as the jhat
tool or the Eclipse Memory Analyzer (MAT)