Java JDK目录下的jmap和jhat工具的使用方式
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{ 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
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
本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Java注解@Cacheable的工作原理
In order to avoid unnecessary query on database it is a common pattern to define a cache in application layer to cache the query result from database. See one example below. Here the application cache is maintained in a custom class CacheContext. public class AccountService1 { private final Logger logger = LoggerFactory.getLogger(AccountService1.class); private CacheContext<Account> accountCacheContext; public Account getAccountByName(String accountName) { Account result = accountCacheCont...
- 下一篇
使用Chrome开发者工具研究JavaScript的垃圾回收机制
I use the following simple JavaScript code to illustrate: var JerryTestArray = []; (function(){ for( var i = 0; i < 100; i++){ JerryTestArray[i] = document.createElement("div"); } })(); Create a new empty tab in your Chrome, and first create a snapshot with empty heap status by click “Take Snapshot” button: The Snapshot1 is generated. Now switch to tab Console, paste the JavaScript code and execute it in console. And switch to Profiles tab again to make the second snapshot: Once done, select ...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Linux系统CentOS6、CentOS7手动修改IP地址
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- Red5直播服务器,属于Java语言的直播服务器
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- Windows10,CentOS7,CentOS8安装Nodejs环境
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果