Java JMX MBeanServer

JMX Java About 6,772 words

功能

MBeanServer可以获取Java服务的运行时的虚拟机信息。

代码

public class MBeanServerTest {

    public static void main(String[] args) {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        try {
            Set<ObjectInstance> objectInstances = mBeanServer.queryMBeans(ObjectName.WILDCARD, null);
            for (ObjectInstance objectInstance : objectInstances) {
                System.out.println("ObjectInstance: " + objectInstance.getObjectName() + "---" + objectInstance.getClassName());
            }

            System.out.println("----------");

            Set<ObjectName> objectNames = mBeanServer.queryNames(ObjectName.WILDCARD, null);
            for (ObjectName objectName : objectNames) {
                System.out.println("ObjectName: " + objectName.getCanonicalName() + "---" + objectName.getKeyPropertyListString() + "---" + objectName.getDomain() + "---" + objectName.getKeyProperty("type") + "---" + objectName.getKeyProperty("name"));
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

}

输出

ObjectInstance: java.lang:name=Metaspace,type=MemoryPool---sun.management.MemoryPoolImpl
ObjectInstance: java.lang:name=CodeHeap 'profiled nmethods',type=MemoryPool---sun.management.MemoryPoolImpl
ObjectInstance: java.lang:type=Runtime---sun.management.RuntimeImpl
ObjectInstance: java.nio:name=mapped,type=BufferPool---sun.management.ManagementFactoryHelper$1
ObjectInstance: java.lang:type=OperatingSystem---com.sun.management.internal.OperatingSystemImpl
ObjectInstance: jdk.management.jfr:type=FlightRecorder---jdk.management.jfr.FlightRecorderMXBeanImpl
ObjectInstance: java.lang:name=Compressed Class Space,type=MemoryPool---sun.management.MemoryPoolImpl
ObjectInstance: java.lang:name=CodeHeap 'non-nmethods',type=MemoryPool---sun.management.MemoryPoolImpl
ObjectInstance: java.lang:name=G1 Eden Space,type=MemoryPool---sun.management.MemoryPoolImpl
ObjectInstance: java.util.logging:type=Logging---sun.management.ManagementFactoryHelper$PlatformLoggingImpl
ObjectInstance: java.lang:type=Compilation---sun.management.CompilationImpl
ObjectInstance: java.lang:name=CodeHeap 'non-profiled nmethods',type=MemoryPool---sun.management.MemoryPoolImpl
ObjectInstance: java.lang:name=Metaspace Manager,type=MemoryManager---sun.management.MemoryManagerImpl
ObjectInstance: JMImplementation:type=MBeanServerDelegate---javax.management.MBeanServerDelegate
ObjectInstance: java.lang:type=ClassLoading---sun.management.ClassLoadingImpl
ObjectInstance: java.lang:name=CodeCacheManager,type=MemoryManager---sun.management.MemoryManagerImpl
ObjectInstance: java.lang:type=Threading---com.sun.management.internal.HotSpotThreadImpl
ObjectInstance: java.nio:name=direct,type=BufferPool---sun.management.ManagementFactoryHelper$1
ObjectInstance: java.lang:name=G1 Old Gen,type=MemoryPool---sun.management.MemoryPoolImpl
ObjectInstance: java.lang:name=G1 Survivor Space,type=MemoryPool---sun.management.MemoryPoolImpl
ObjectInstance: java.lang:name=G1 Young Generation,type=GarbageCollector---com.sun.management.internal.GarbageCollectorExtImpl
ObjectInstance: java.lang:type=Memory---sun.management.MemoryImpl
ObjectInstance: com.sun.management:type=HotSpotDiagnostic---com.sun.management.internal.HotSpotDiagnostic
ObjectInstance: java.lang:name=G1 Old Generation,type=GarbageCollector---com.sun.management.internal.GarbageCollectorExtImpl
ObjectInstance: com.sun.management:type=DiagnosticCommand---com.sun.management.internal.DiagnosticCommandImpl
----------
ObjectName: JMImplementation:type=MBeanServerDelegate---type=MBeanServerDelegate---JMImplementation---MBeanServerDelegate---null
ObjectName: java.lang:type=Runtime---type=Runtime---java.lang---Runtime---null
ObjectName: java.lang:type=Threading---type=Threading---java.lang---Threading---null
ObjectName: java.lang:type=OperatingSystem---type=OperatingSystem---java.lang---OperatingSystem---null
ObjectName: java.nio:name=direct,type=BufferPool---name=direct,type=BufferPool---java.nio---BufferPool---direct
ObjectName: java.lang:type=Compilation---type=Compilation---java.lang---Compilation---null
ObjectName: java.lang:name=G1 Young Generation,type=GarbageCollector---name=G1 Young Generation,type=GarbageCollector---java.lang---GarbageCollector---G1 Young Generation
ObjectName: java.lang:name=CodeCacheManager,type=MemoryManager---name=CodeCacheManager,type=MemoryManager---java.lang---MemoryManager---CodeCacheManager
ObjectName: java.lang:name=G1 Old Gen,type=MemoryPool---name=G1 Old Gen,type=MemoryPool---java.lang---MemoryPool---G1 Old Gen
ObjectName: java.util.logging:type=Logging---type=Logging---java.util.logging---Logging---null
ObjectName: java.lang:name=G1 Old Generation,type=GarbageCollector---name=G1 Old Generation,type=GarbageCollector---java.lang---GarbageCollector---G1 Old Generation
ObjectName: java.lang:type=ClassLoading---type=ClassLoading---java.lang---ClassLoading---null
ObjectName: java.lang:name=Metaspace Manager,type=MemoryManager---name=Metaspace Manager,type=MemoryManager---java.lang---MemoryManager---Metaspace Manager
ObjectName: java.lang:name=G1 Survivor Space,type=MemoryPool---name=G1 Survivor Space,type=MemoryPool---java.lang---MemoryPool---G1 Survivor Space
ObjectName: java.lang:name=Metaspace,type=MemoryPool---name=Metaspace,type=MemoryPool---java.lang---MemoryPool---Metaspace
ObjectName: java.lang:name=CodeHeap 'profiled nmethods',type=MemoryPool---name=CodeHeap 'profiled nmethods',type=MemoryPool---java.lang---MemoryPool---CodeHeap 'profiled nmethods'
ObjectName: java.lang:name=CodeHeap 'non-nmethods',type=MemoryPool---name=CodeHeap 'non-nmethods',type=MemoryPool---java.lang---MemoryPool---CodeHeap 'non-nmethods'
ObjectName: java.lang:name=Compressed Class Space,type=MemoryPool---name=Compressed Class Space,type=MemoryPool---java.lang---MemoryPool---Compressed Class Space
ObjectName: java.lang:type=Memory---type=Memory---java.lang---Memory---null
ObjectName: java.lang:name=G1 Eden Space,type=MemoryPool---name=G1 Eden Space,type=MemoryPool---java.lang---MemoryPool---G1 Eden Space
ObjectName: java.nio:name=mapped,type=BufferPool---name=mapped,type=BufferPool---java.nio---BufferPool---mapped
ObjectName: com.sun.management:type=DiagnosticCommand---type=DiagnosticCommand---com.sun.management---DiagnosticCommand---null
ObjectName: java.lang:name=CodeHeap 'non-profiled nmethods',type=MemoryPool---name=CodeHeap 'non-profiled nmethods',type=MemoryPool---java.lang---MemoryPool---CodeHeap 'non-profiled nmethods'
ObjectName: com.sun.management:type=HotSpotDiagnostic---type=HotSpotDiagnostic---com.sun.management---HotSpotDiagnostic---null
ObjectName: jdk.management.jfr:type=FlightRecorder---type=FlightRecorder---jdk.management.jfr---FlightRecorder---null
Views: 283 · Posted: 2024-01-11

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

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

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


Today On History
Browsing Refresh