我知道使用jconsole附加到java进程以获取内存信息.具体来说,我是以编程方式获取有关各种内存池的信息,因此我可以将其与监控应用程序联系起来.
谢谢!
解决方法:
谢谢mattk – 我基本上做了这个:-)
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;
}