1

Is there a way for MBean Registration with same(Single) object name for multiple objects of same class ? What is the simpler way ?

1 Answers1

0

No, there isn't. If you try to register an instance which has the same name of another one that was already registered, a javax.management.InstanceAlreadyExistsException will be thrown.

You have to use a different name for the second instance as follows:

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

ObjectName name = new ObjectName("firstInstance:type=Hello");
Hello mbean = new Hello();
mbs.registerMBean(mbean, name);

ObjectName name2 = new ObjectName("secondInstance:type=Hello");
Hello mbean2 = new Hello();
mbs.registerMBean(mbean2, name2);
hbelmiro
  • 987
  • 11
  • 31