} else { if (log.isDebugEnabled()) { log.debug("Not using jmx: useMBeanServer is false"); }
    protected synchronized MBeanServer findMBeanServer() {        MBeanServer result = null;        // create the mbean server and start an rmi connector        if (useMBeanServer) {            try {                // lets piggy back on another MBeanServer - we could be in an appserver!                List list = MBeanServerFactory.findMBeanServer(null);                if (list != null && list.size() > 0) {                    result = (MBeanServer) list.get(0);                }                if (result == null && createMBeanServer) {                    result = MBeanServerFactory.createMBeanServer(jmxDomainName);                    locallyCreateMBeanServer = true;                    // Register and start the rmiregistry MBean, needed by JSR 160 RMIConnectorServer                    ObjectName namingName = ObjectName.getInstance("naming:type=rmiregistry");                    if (!result.isRegistered(namingName)) {                        try {                            // Do not use the createMBean as the mx4j jar may not be in the                             // same class loader than the server                            Class cl = Class.forName("mx4j.tools.naming.NamingService");                            result.registerMBean(cl.newInstance(), namingName);                            //result.createMBean("mx4j.tools.naming.NamingService", namingName, null);                            // set the naming port                            Attribute attr = new Attribute("Port", new Integer(namingPort));                            result.setAttribute(namingName, attr);                            result.invoke(namingName, "start", null, null);                        }                        catch (Exception e) {                            // could already be in use                            log.debug("Could not start naming service", e);                            // Now, make sure a registry is loaded                            try {                                LocateRegistry.createRegistry(namingPort);                            }                            catch (Throwable t) {                                // proably exists already                                log.debug("Failed to create local registry", t);                            }                        }                        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + namingPort                                + jndiPath);                        // Create and start the RMIConnectorServer                        connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, result);                        connectorServer.start();                    }                    /*                    // Now, make sure a registry is loaded                    try {                        LocateRegistry.createRegistry(namingPort);                    }                    catch (Throwable t) {                        // proably exists already                        log.debug("Failed to create local registry", t);                    }                    // Create and start the RMIConnectorServer                    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + namingPort                            + jndiPath);                    connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, result);                    connectorServer.start();                    */                }            }            catch (NoClassDefFoundError e) {                log.error("Could not load MBeanServer", e);            }            /*            catch (JMException e) {                log.error("Could not start the remote: JMX ConnectorServer", e);            }            */            catch (MalformedURLException e) {                log.error("Bad URL:", e);            }            catch (IOException e) {                log.error("Could not start the remote: JMX ConnectorServer", e);            }            catch (Throwable e) {                // probably don't have access to system properties                log.error("Failed to initialize MBeanServer", e);            }        }        return result;    }