Fixing JMX re-registration issue
import java.lang.management.ManagementFactory;
+import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
public MBean register(Object bean) {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- try {
MBean mBean = new MBean(bean);
+ try {
mbs.registerMBean(mBean, mBean.getObjectName());
return mBean;
+ } catch (InstanceAlreadyExistsException t) {
+ return mBean;
} catch (Throwable t) {
t.printStackTrace();
return null;
