Home >Java >javaTutorial >How to use JDK's built-in jmap and jhat to monitor the running status of Java processes
The content of this article is about how to use JDK’s own jmap and jhat to monitor the running status of Java processes. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
For running Java processes, JDK comes with many tools that allow Java developers to monitor various states of the running process, such as how many object instances are created inside the process, consumption How much memory is required, etc.
This article is written based on JDK1.8.
I wrote the simplest Java class below, which contains an infinite loop that increases the value of a counter every 5 seconds.
package jmap; class Tool{ private int count = 0; public void Run() throws InterruptedException{ while(true){ System.out.println("Hello: " + this.count++); Thread.sleep(5000); } } } public class JMapTest { public static void main(String[] args) throws InterruptedException { Tool tool = new Tool(); tool.Run(); } }
Execute this application in Eclipse.
The following describes how to use jmap and jhat to monitor this running process.
1. First get the ID of this Java running process: 15392. I directly used the Task Manager that comes with Windows to obtain the process ID.
2. Use the following command line:
jmap -dump:format=b,file=c:tempheapstatus.bin 15392
jmap is a tool provided by JDK and is located in the bin folder of the JDK installation directory.
Executing the command line will generate a heap dump file: headstatus.bin
3. Now you can use another JDK tool, jhat, to read this dump file and parse it. Use the command line:
jhat c:tempheapstatus.bin
The above is the detailed content of How to use JDK's built-in jmap and jhat to monitor the running status of Java processes. For more information, please follow other related articles on the PHP Chinese website!