How do I programmatically find out my PermGen space usage?

℡╲_俬逩灬. 提交于 2019-12-03 01:12:08

问题


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 program is using at various points. Is there a way of finding out this information programmatically?


回答1:


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.




回答2:


Try ManagementFactory.getMemoryPoolMXBeans().



来源:https://stackoverflow.com/questions/697336/how-do-i-programmatically-find-out-my-permgen-space-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!