Java JMX MemoryManagerMXBean

JMX Java About 1,620 words

功能

MemoryManagerMXBean可以获取Java服务的内存管理器信息:

  • CodeCacheManager: 代码缓存管理器
  • Metaspace Manager: 元数据管理器
  • G1 Young Generation: G1年轻代
  • G1 Old Generation: G1老年代

代码

public class MemoryManagerMXBeansTest {

    public static void main(String[] args) {
        List<MemoryManagerMXBean> memoryManagerMXBeans = ManagementFactory.getMemoryManagerMXBeans();
        for (MemoryManagerMXBean memoryManagerMXBean : memoryManagerMXBeans) {
            System.out.println("name: " + memoryManagerMXBean.getName());
            System.out.println("isValid: " + memoryManagerMXBean.isValid());
            System.out.println("objectName: " + memoryManagerMXBean.getObjectName());
            System.out.println("memoryPoolNames: " + Arrays.toString(memoryManagerMXBean.getMemoryPoolNames()));
            System.out.println("----------------");
        }
    }

}

输出

name: CodeCacheManager
isValid: true
objectName: java.lang:type=MemoryManager,name=CodeCacheManager
memoryPoolNames: [CodeHeap 'non-nmethods', CodeHeap 'profiled nmethods', CodeHeap 'non-profiled nmethods']
----------------
name: Metaspace Manager
isValid: true
objectName: java.lang:type=MemoryManager,name=Metaspace Manager
memoryPoolNames: [Metaspace, Compressed Class Space]
----------------
name: G1 Young Generation
isValid: true
objectName: java.lang:type=GarbageCollector,name=G1 Young Generation
memoryPoolNames: [G1 Eden Space, G1 Survivor Space, G1 Old Gen]
----------------
name: G1 Old Generation
isValid: true
objectName: java.lang:type=GarbageCollector,name=G1 Old Generation
memoryPoolNames: [G1 Eden Space, G1 Survivor Space, G1 Old Gen]
----------------
Views: 629 · Posted: 2024-01-05

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh