Programatically get heap info using jmx with java 5

前端 未结 2 2084
你的背包
你的背包 2020-12-29 16:08

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

相关标签:
2条回答
  • 2020-12-29 16:49

    Check out java.lang.management.MemoryPoolMXBean and related classes.

    0 讨论(0)
  • 2020-12-29 16:51

    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;
    
    }
    
    0 讨论(0)
提交回复
热议问题