我知道使用jconsole附加到Java进程以获取内存信息。具体来说,我是通过编程方式获取有关各种内存池的信息,因此可以将其绑定(bind)到监视应用程序。

谢谢!

最佳答案

谢谢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;

}

10-04 19:25