ArrayList servers=MBeanServerFactory.findMBeanServer("jboss"); if(servers != null && servers.size() > 0) { return (MBeanServer)servers.get(0);
ArrayList servers=MBeanServerFactory.findMBeanServer(null); if(servers == null || servers.size() == 0) return null;   for(int i=0; i < servers.size(); i++) { MBeanServer srv=(MBeanServer)servers.get(i); if(srv.getDefaultDomain().equalsIgnoreCase("jboss")) return srv;
    private MBeanServer getMBeanServer() {        ArrayList servers=MBeanServerFactory.findMBeanServer("jboss"); // return JBoss server if available        if(servers != null && servers.size() > 0) {            return (MBeanServer)servers.get(0);        }                servers=MBeanServerFactory.findMBeanServer(null); // return any available server        if(servers != null && servers.size() > 0) {            return (MBeanServer)servers.get(0);        }        return null;    }