How do I programmatically find out my PermGen space usage?

前端 未结 2 432
难免孤独
难免孤独 2021-01-30 07:28

I\'m trying to diagnose a java.lang.OutOfMemoryError: PermGen Space error when running on Sun\'s Hotspot JVM, and would like to know how much PermGen space my progr

相关标签:
2条回答
  • 2021-01-30 07:52

    Try ManagementFactory.getMemoryPoolMXBeans().

    0 讨论(0)
  • 2021-01-30 07:56

    You can use something like this:

    Iterator<MemoryPoolMXBean> iter = ManagementFactory.getMemoryPoolMXBeans().iterator();
    while (iter.hasNext())
    {
        MemoryPoolMXBean item = iter.next();
        String name = item.getName();
        MemoryType type = item.getType();
        MemoryUsage usage = item.getUsage();
        MemoryUsage peak = item.getPeakUsage();
        MemoryUsage collections = item.getCollectionUsage();
    }
    

    This will give you all types of memory. You are interested in "Perm Gen" type.

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