ManagementFactory.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:openjdk-jdk10 作者:
/**
 * Returns the platform {@link javax.management.MBeanServer MBeanServer}.
 * On the first call to this method, it first creates the platform
 * {@code MBeanServer} by calling the
 * {@link javax.management.MBeanServerFactory#createMBeanServer
 * MBeanServerFactory.createMBeanServer}
 * method and registers each platform MXBean in this platform
 * {@code MBeanServer} with its
 * {@link PlatformManagedObject#getObjectName ObjectName}.
 * This method, in subsequent calls, will simply return the
 * initially created platform {@code MBeanServer}.
 * <p>
 * MXBeans that get created and destroyed dynamically, for example,
 * memory {@link MemoryPoolMXBean pools} and
 * {@link MemoryManagerMXBean managers},
 * will automatically be registered and deregistered into the platform
 * {@code MBeanServer}.
 * <p>
 * If the system property {@code javax.management.builder.initial}
 * is set, the platform {@code MBeanServer} creation will be done
 * by the specified {@link javax.management.MBeanServerBuilder}.
 * <p>
 * It is recommended that this platform MBeanServer also be used
 * to register other application managed beans
 * besides the platform MXBeans.
 * This will allow all MBeans to be published through the same
 * {@code MBeanServer} and hence allow for easier network publishing
 * and discovery.
 * Name conflicts with the platform MXBeans should be avoided.
 *
 * @return the platform {@code MBeanServer}; the platform
 *         MXBeans are registered into the platform {@code MBeanServer}
 *         at the first time this method is called.
 *
 * @exception SecurityException if there is a security manager
 * and the caller does not have the permission required by
 * {@link javax.management.MBeanServerFactory#createMBeanServer}.
 *
 * @see javax.management.MBeanServerFactory
 * @see javax.management.MBeanServerFactory#createMBeanServer
 */
public static synchronized MBeanServer getPlatformMBeanServer() {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Permission perm = new MBeanServerPermission("createMBeanServer");
        sm.checkPermission(perm);
    }

    if (platformMBeanServer == null) {
        platformMBeanServer = MBeanServerFactory.createMBeanServer();
        platformComponents()
                .stream()
                .filter(PlatformComponent::shouldRegister)
                .flatMap(pc -> pc.nameToMBeanMap().entrySet().stream())
                .forEach(entry -> addMXBean(platformMBeanServer, entry.getKey(), entry.getValue()));
    }
    return platformMBeanServer;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号