如何以编程方式找出我的PermGen空间使用情况? [英] How do I programmatically find out my PermGen space usage?

查看:111
本文介绍了如何以编程方式找出我的PermGen空间使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Sun的Hotspot JVM上运行时诊断 java.lang.OutOfMemoryError:PermGen Space 错误,并且想知道我的程序有多少PermGen空间正在各个方面使用。有没有办法以编程方式查找此信息?

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?

推荐答案

您可以使用以下内容:

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();
}

这将为您提供所有类型的内存。您对Perm Gen类型感兴趣。

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

这篇关于如何以编程方式找出我的PermGen空间使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆