前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Java JDK目录下的jmap和jhat工具的使用方式

Java JDK目录下的jmap和jhat工具的使用方式

作者头像
Jerry Wang
发布2020-05-06 21:13:34
4390
发布2020-05-06 21:13:34
举报

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:

代码语言:javascript
复制
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();
	}
}

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

(2) use command line

代码语言:javascript
复制
jmap -dump:format=b,file=c:\temp\heapstatus.bin 1539

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:

代码语言:javascript
复制
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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-05-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档