从代码中找出NewSize是什么

时间:2014-02-06 08:00:49

标签: java jvm jvm-arguments

是否可以像查找堆大小一样显示java NewSize参数?

我知道可以使用以下命令找到堆大小:

Runtime.getRuntime().maxMemory();

NewSize有类似的内容吗?

1 个答案:

答案 0 :(得分:1)

您希望MemoryPoolMXBean获取伊甸园空间和幸存者空间的数值:

for(java.lang.management.MemoryPoolMXBean memoryPoolMXBean :java.lang.management.ManagementFactory.getMemoryPoolMXBeans())
{
    System.out.println("");
    try
    {
        System.out.println("PoolName\t" + memoryPoolMXBean.getName());
        System.out.println("Commited\t" + memoryPoolMXBean.getCollectionUsage().getCommitted());
        System.out.println("Init\t" + memoryPoolMXBean.getCollectionUsage().getInit());
        System.out.println("Max\t" + memoryPoolMXBean.getCollectionUsage().getMax());
        System.out.println("Used\t" + memoryPoolMXBean.getCollectionUsage().getUsed());
    }
    catch (NullPointerException npex)
    {
        npex.printStackTrace();
    }
}

<强>输出:

PoolName    Code Cache
java.lang.NullPointerException
    at com.github.lyubent.example.App.main(App.java:40)

PoolName    Par Eden Space
Commited    0
Init    335544320
Max 335544320
Used    0

PoolName    Par Survivor Space
Commited    0
Init    41943040
Max 41943040
Used    0

PoolName    CMS Old Gen
Commited    0
Init    1728053248
Max 1728053248
Used    0

PoolName    CMS Perm Gen
Commited    0
Init    21757952
Max 85983232
Used    0