code: public void closeMBeans() {
      try {
        for (final ObjectName name : registeredMBeans) {
          getMbeanServer().unregisterMBean(name);
          logger.info("Jmx MBean " + name.getCanonicalName() + " unregistered.");
        }
      } catch (final Exception e) {
        logger.error("Failed to cleanup MBeanServer", e);
      }
    }
docs: Close all registered MBeans