使用JDK工具jmap和jhat监控Java进程

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:


使用JDK工具jmap和jhat监控Java进程使用JDK工具jmap和jhat监控Java进程使用JDK工具jmap和jhat监控Java进程使用JDK工具jmap和jhat监控Java进程

使用JDK工具jmap和jhat监控Java进程

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


使用JDK工具jmap和jhat监控Java进程


(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:


使用JDK工具jmap和jhat监控Java进程


heap bin file is generated now:


使用JDK工具jmap和jhat监控Java进程


(3) Use another tool jhat to parse the bin file:

jhat c:\temp\heapstatus.bin


使用JDK工具jmap和jhat监控Java进程


Then access localhost:7000 in browser:


使用JDK工具jmap和jhat监控Java进程


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.


使用JDK工具jmap和jhat监控Java进程


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


使用JDK工具jmap和jhat监控Java进程


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


使用JDK工具jmap和jhat监控Java进程


Drag your bin file into the view and the heap file will be parsed automatically.

Click “Find object by address”:


使用JDK工具jmap和jhat监控Java进程


Type address of object instance you want to inspect:


使用JDK工具jmap和jhat监控Java进程


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


使用JDK工具jmap和jhat监控Java进程

上一篇:Vuex.Mutation


下一篇:MyBatis源码解析之基础模块—TypeHandler