Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


Java JMX MemoryManagerMXBean

JMX Java 大约 1620 字

功能

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]
----------------
阅读 121 · 发布于 2024-01-05

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

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

扫描二维码关注我
昵称:
随便看看 换一批