首页 > 应用开发 > IT综合 > 使用JDK工具jmap和jhat监控Java进程


原创 IT综合 作者:i042416 时间:2020-09-20 12:09:47 0 删除 编辑

Suppose you have a running Java process and you would like to inspect its running status, for example how many object instance are created or memory consumption status, you can use some standard tool provided by JDK.

This blog is written based on JDK 1.8. The sample code I am using to simulate a endless running process:

package jmap;class Tool{
    private int count = 0;
    public void Run() throws InterruptedException{
            System.out.println("Hello: " + this.count++);
    }}public class JMapTest {
    public static void main(String[] args) throws InterruptedException {
        Tool tool = new Tool();

(1) First get process id found in task manager: 15392

(2) use command line jmap -dump:format=b,file=c:\temp\heapstatus.bin 15392 jmap is a standard tool provided by JDK in this folder in my laptop:

heap bin file is generated now:

(3) Use another tool jhat to parse the bin file: jhat c:\temp\heapstatus.bin

Then access localhost:7000 in browser:

Click hyperlink class jmap.Tool, now I can find out that the instance of my tool class @0x7166babd8 has member attribute count with value 49.

(4) There is a plugin in Eclipse MAT – Memory Analyzer Tool which can achieve the same.

Once plugin is installed, you can make them visible in “Show View”:

Drag your bin file into the view and the heap file will be parsed automatically. Click “Find object by address”:

Type address of object instance you want to inspect:

You can get the same result as you get previously in localhost:7000


来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录


  • 博文量
  • 访问量