通过Java 5使用jmx以编程方式获取堆信息 [英] Programatically get heap info using jmx with java 5
本文介绍了通过Java 5使用jmx以编程方式获取堆信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道使用jconsole附加到Java进程来获取内存信息.具体来说,我是通过编程方式获取有关各种内存池的信息,因此可以将其绑定到监视应用程序.
I am aware of using jconsole to attach to a java process to get memory information. Specifically I'm after getting information on the various memory pools programatically so I can tie it to a monitoring application.
谢谢!
推荐答案
感谢mattk-我基本上是这样做的:-)
Thanks mattk - I wound up doing basically this :-)
List memBeans = ManagementFactory.getMemoryPoolMXBeans();
for (Iterator i = memBeans.iterator(); i.hasNext(); ) {
MemoryPoolMXBean mpool = (MemoryPoolMXBean)i.next();
MemoryUsage usage = mpool.getUsage();
String name = mpool.getName();
float init = usage.getInit()/1000;
float used = usage.getUsed()/1000;
float committed = usage.getCommitted()/1000;
float max = usage.getMax()/1000;
float pctUsed = (used / max)*100;
float pctCommitted = (committed / max)*100;
}
这篇关于通过Java 5使用jmx以编程方式获取堆信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文