返回顶部

收藏

列出 JVM 中所有的 MBeans

更多

[Java]代码

package cn.outofmemory.snippets.enterprise;

import java.lang.management.ManagementFactory;
import java.util.Iterator;
import java.util.Set;

import javax.management.MBeanServer;
import javax.management.ObjectInstance;

public class ListAllJVMMBeans {

    public static void main(String[] args) throws Exception {

        MBeanServer server = ManagementFactory.getPlatformMBeanServer();

        Set instances = server.queryMBeans(null, null);

        Iterator iterator = instances.iterator();

        while (iterator.hasNext()) {
            ObjectInstance instance = iterator.next();
            System.out.println("MBean Found:");
            System.out.println("Class Name:\t" + instance.getClassName());
            System.out.println("Object Name:\t" + instance.getObjectName());
            System.out.println("****************************************");
        }

    }

}

输出结果

MBean Found:
Class Name: com.sun.management.OperatingSystem
Object Name:    java.lang:type=OperatingSystem
****************************************
MBean Found:
Class Name: sun.management.MemoryPoolImpl
Object Name:    java.lang:type=MemoryPool,name=Tenured Gen
****************************************
MBean Found:
Class Name: sun.management.MemoryPoolImpl
Object Name:    java.lang:type=MemoryPool,name=Perm Gen
****************************************
MBean Found:
Class Name: java.util.logging.Logging
Object Name:    java.util.logging:type=Logging
****************************************
MBean Found:
Class Name: sun.management.CompilationImpl
Object Name:    java.lang:type=Compilation
****************************************
MBean Found:
Class Name: javax.management.MBeanServerDelegate
Object Name:    JMImplementation:type=MBeanServerDelegate
****************************************
MBean Found:
Class Name: sun.management.MemoryImpl
Object Name:    java.lang:type=Memory
****************************************
MBean Found:
Class Name: sun.management.MemoryPoolImpl
Object Name:    java.lang:type=MemoryPool,name=Survivor Space
****************************************
MBean Found:
Class Name: sun.management.RuntimeImpl
Object Name:    java.lang:type=Runtime
****************************************
MBean Found:
Class Name: sun.management.GarbageCollectorImpl
Object Name:    java.lang:type=GarbageCollector,name=Copy
****************************************
MBean Found:
Class Name: sun.management.MemoryPoolImpl
Object Name:    java.lang:type=MemoryPool,name=Eden Space
****************************************
MBean Found:
Class Name: sun.management.GarbageCollectorImpl
Object Name:    java.lang:type=GarbageCollector,name=MarkSweepCompact
****************************************
MBean Found:
Class Name: sun.management.ThreadImpl
Object Name:    java.lang:type=Threading
****************************************
MBean Found:
Class Name: sun.management.MemoryPoolImpl
Object Name:    java.lang:type=MemoryPool,name=Perm Gen [shared-ro]
****************************************
MBean Found:
Class Name: sun.management.MemoryPoolImpl
Object Name:    java.lang:type=MemoryPool,name=Perm Gen [shared-rw]
****************************************
MBean Found:
Class Name: sun.management.HotSpotDiagnostic
Object Name:    com.sun.management:type=HotSpotDiagnostic
****************************************
MBean Found:
Class Name: sun.management.ClassLoadingImpl
Object Name:    java.lang:type=ClassLoading
****************************************
MBean Found:
Class Name: sun.management.MemoryManagerImpl
Object Name:    java.lang:type=MemoryManager,name=CodeCacheManager
****************************************
MBean Found:
Class Name: sun.management.MemoryPoolImpl
Object Name:    java.lang:type=MemoryPool,name=Code Cache
****************************************

标签:jvm,java

收藏

0人收藏

支持

0

反对

0