public void startConnectorServer(int rmiRegistryPort, int rmiConnectorPort) throws IOException {
    boolean rmiSSL = false;
    boolean authenticate = true;
    String passwordFile = null;
    String accessFile = null;

    System.setProperty("java.rmi.server.randomIDs", "true");

    String rmiSSLValue = System.getProperty("com.sun.management.jmxremote.ssl", "false");
    rmiSSL = Boolean.parseBoolean(rmiSSLValue);

    String authenticateValue =
      System.getProperty("com.sun.management.jmxremote.authenticate", "false");
    authenticate = Boolean.parseBoolean(authenticateValue);

    passwordFile = System.getProperty("com.sun.management.jmxremote.password.file");
    accessFile = System.getProperty("com.sun.management.jmxremote.access.file");

    LOG.info("rmiSSL:" + rmiSSLValue + ",authenticate:" + authenticateValue + ",passwordFile:"
      + passwordFile + ",accessFile:" + accessFile);

    // Environment map
    HashMap<String, Object> jmxEnv = new HashMap<>();

    RMIClientSocketFactory csf = null;
    RMIServerSocketFactory ssf = null;

    if (rmiSSL) {
      if (rmiRegistryPort == rmiConnectorPort) {
        throw new IOException(
          "SSL is enabled. " + "rmiConnectorPort cannot share with the rmiRegistryPort!");
      }
      csf = new SslRMIClientSocketFactorySecure();
      ssf = new SslRMIServerSocketFactorySecure();
    }

    if (csf != null) {
      jmxEnv.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
    }
    if (ssf != null) {
      jmxEnv.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
    }

    // Configure authentication
    if (authenticate) {
      jmxEnv.put("jmx.remote.x.password.file", passwordFile);
      jmxEnv.put("jmx.remote.x.access.file", accessFile);
    }

    // Create the RMI registry
    rmiRegistry = LocateRegistry.createRegistry(rmiRegistryPort);
    // Retrieve the PlatformMBeanServer.
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    // Build jmxURL
    JMXServiceURL serviceUrl = buildJMXServiceURL(rmiRegistryPort, rmiConnectorPort);

    try {
      // Start the JMXListener with the connection string
      synchronized (JMXListener.class) {
        if (JMX_CS != null) {
          throw new RuntimeException("Started by another thread?");
        }
        JMX_CS = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl, jmxEnv, mbs);
        JMX_CS.start();
      }
      LOG.info("JMXConnectorServer started!");
    } catch (IOException e) {
      LOG.error("Failed start of JMXConnectorServer!", e);
      // deregister the RMI registry
      if (rmiRegistry != null) {
        UnicastRemoteObject.unexportObject(rmiRegistry, true);
      }
    }

  }
workaround for HBASE-11146 master and regionserver are in 1 JVM in standalone mode only 1 JMX
instance is allowed, otherwise there is port conflict even if we only load regionserver
coprocessor on master
hbase-server/src/main/java/org/apache/hadoop/hbase/JMXListener.java