public static void registerMBean(Object mbean,Class<?> mbeanClass){
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  try {
    if (logger.isDebugEnabled())     logger.debug("Registering mbean: " + mbean.getClass());
    ObjectName name=generateMBeanObjectName(mbeanClass);
    if (mbs.isRegistered(name))     mbs.unregisterMBean(name);
    mbs.registerMBean(mbean,name);
  }
 catch (  Exception e) {
    throw new ServerRuntimeException(String.format("Unable to register mbean for class %s because '%s'",mbeanClass.getName(),e),e);
  }
}

public static void registerMBean ( Object mbean , Class < ? > mbeanClass ) { MBeanServer mbs = ManagementFactory . getPlatformMBeanServer ( ) ; try { if ( logger . isDebugEnabled ( ) ) logger . debug ( "Registering mbean: " + mbean . getClass ( ) ) ; ObjectName name = generateMBeanObjectName ( mbeanClass ) ; if ( mbs . isRegistered ( name ) ) mbs . unregisterMBean ( name ) ; mbs . registerMBean ( mbean , name ) ; } catch ( Exception e ) { throw new ServerRuntimeException ( String . format ( "Unable to register mbean for class %s because '%s'" , mbeanClass . getName ( ) , e ) , e ) ; } }
server helper method to register a jmx mbean . mbeans are registered by a combination of their mbean interface and the custom mbeanname argument . the mbeanname permits multiple mbeans to be registered under the same name .
