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 and heap dump of a Java process on Windows that is not running in a console, you can use the jstack and jcmd 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. Note: To attach to a Java process on Windows, your command prompt must run with the same user privileges as the process (or as Administrator).
To get a thread dump of a Java process with PID 12345, you can use the following command:
jstack 12345This 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.txtThis will save the thread dump to the file threaddump.txt.
To get a heap dump of a Java process, use the jcmd tool. Note that jmap is deprecated in JDK 9+ and removed in JDK 11+. The jcmd 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 jcmd, 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:
jcmd 12345 GC.heap_dump heapdump.binThis 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 Eclipse Memory Analyzer (MAT) or VisualVM, to inspect the file.