How to get the max sizes of the heap and permgen from the JVM?

前端 未结 3 1653
有刺的猬
有刺的猬 2020-12-31 20:42

I am trying to find out programatically the max permgen and max heap size with which a the JVM for my program has been invoked, not what is currently available to them.

相关标签:
3条回答
  • 2020-12-31 21:13

    As for eclipse, try looking for a profiling tool. I think NetBeans has one by default.

    0 讨论(0)
  • 2020-12-31 21:22

    Try this ones:

    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    mem.getHeapMemoryUsage().getUsed();
    mem.getNonHeapMemoryUsage().getUsed();
    

    But they only offer snapshot data, not a cummulated value.

    0 讨论(0)
  • 2020-12-31 21:27

    Try something like this for max perm gen:

    public static long getPermGenMax() {
        for (MemoryPoolMXBean mx : ManagementFactory.getMemoryPoolMXBeans()) {
            if ("Perm Gen".equals(mx.getName())) {
                return mx.getUsage().getMax();
            }
        }
        throw new RuntimeException("Perm gen not found");
    }
    

    For max heap, you can get this from Runtime, though you can also use the appropriate MemoryPoolMXBean.

    0 讨论(0)
提交回复
热议问题