Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use jmap and jhat included with JDK to monitor running Java processes

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to use JDK's own jmap and jhat to monitor running Java processes". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use jmap and jhat included with JDK to monitor running Java processes".

This article is based on JDK1.8.

I write the simplest Java class below, which contains an infinite loop that increments 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 the application in Eclipse.

Here's how to monitor this running process using jmap and jhat.

1. First get the ID:15392 of the Java running process. I get the process ID directly from the task manager that comes with Windows.

Use jmap and jhat included with JDK to monitor running Java processes

two。 Use the following command line:

Jmap-dump:format=b,file=c:\ temp\ heapstatus.bin 15392

Jmap is a tool provided by JDK and is located in the bin folder of the JDK installation directory.

Execute the command line, resulting in a heap dump file: headstatus.bin

3. You can now use another JDK tool, jhat, to read the dump file and parse it. Use the command line:

Jhat c:\ temp\ heapstatus.bin

After parsing, the output printed by jhat prompts us to Snapshot resolved, which can be viewed from port 7000 on the local server.

Visit http://localhost:7000 and you can see the result of jmap parsing.

Localhost:7000 in browser:

Click the hyperlink "jmap Tool" to enter the details: the following figure means that the member variable of the instance of my Tool class @ 0x7166babd8, that is, the value of the counter has accumulated to 49.

4. If you don't like the command line, you can also use an Eclipse plug-in, MAT-Memory Analyzer Tool, to do the same functions as jmap and jhat commands.

After this plug-in is installed, there will be an additional view in Eclipse:

Directly drag the heap dump file generated by jmap into the MAT view, and you can automatically parse and display the results.

Click the button "Find object by address":

You can also see the details of the object instances you saw earlier in localhost:7000:

You can get the same result as you get previously in

At this point, I believe you have a deeper understanding of "how to use JDK's own jmap and jhat to monitor running Java processes". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report