code: private static void unregister(ObjectName objectName) {
      MBeanServer server = ManagementFactory.getPlatformMBeanServer();
      try {
        for (ObjectName name : server.queryNames(objectName, null)) {
          server.unregisterMBean(name);
        }
      } catch (MBeanRegistrationException | InstanceNotFoundException e) {
        throw new CacheException("Error unregistering " + objectName, e);
      }
    }
docs: Unregisters the management bean(s) with the given object name.