如何以编程方式找出我的PermGen空间使用情况?

时间:2022-12-25 17:19:30

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?

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

2 个解决方案

#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.

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

#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.

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

#2