Here you can find the source of getMBeanServer()
public static MBeanServer getMBeanServer()
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; public class Main { public static final String DOMAIN_NAME = "TankWar"; public static MBeanServer getMBeanServer() { ArrayList<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null); if (servers != null && !servers.isEmpty()) { for (int i = 0; i < servers.size(); i++) { MBeanServer server = servers.get(i); if (DOMAIN_NAME.equalsIgnoreCase(server.getDefaultDomain())) { return server; }//from w ww . ja v a2 s. c om } return (MBeanServer) servers.get(0); } else { return MBeanServerFactory.createMBeanServer(DOMAIN_NAME); } } }