5
我想構建一個MemoryWarningSystem,如許多文章中所述: 如在http://www.javaspecialists.eu/archive/Issue092.html中那樣。如何識別暫住空間
因此,我想找出像這樣的終身空間:
private MemoryPoolMXBean findTenuredGenPool() {
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
if(pool is tenured space)
return tenured
}
}
我已經看到了兩種不同的方法來識別終身空間
- 檢查池名稱等於「PS老代」和/或「終身代」。
- 檢查是否 「
pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()
」
問題與1:什麼CMS老根?其他終身空間呢?我是否應該將它們全部添加到終身名稱列表中?
問題2:這是檢索終身空間的「安全」方式嗎?它可靠嗎?
謝謝!