0

I am trying to monitor the objects of my application via JMX in JConsole. But in the JConsole i am not able to see the multiple objects of a same class. Here is my code:

ApplicationCache cache1 = new ApplicationCache();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("org.javalobby.tnt.jmx:type=ApplicationCacheMBean1");
mbs.registerMBean(cache1, name);
imitateActivity(cache1);

ApplicationCache cache2 = new ApplicationCache();
mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name2 = new ObjectName("org.javalobby.tnt.jmx:type=ApplicationCacheMBean2");
mbs.registerMBean(cache2, name2);
imitateActivity(cache2);

In the JConsole UI i am able to see the info of ApplicationCacheMBean1 only. There is no info about ApplicationCacheMBean2. Please help.

Gray
  • 115,027
  • 24
  • 293
  • 354
G.S
  • 10,413
  • 7
  • 36
  • 52
  • Are you sure "immitateActivity()" method is asynchronous? That your application does not stop there and simply does not progress to the registration of the second MBean? BTW, you don't need to re-retrieve the MBeanServer via ManagementFactory.getPlatformMBeanServer(). The platform MBean server is effectively a singleton and does not change in time. – JB- Apr 04 '13 at 13:11

1 Answers1

0

I would change type= to be name=. If you look at the ObjectName javadocs, all their samples have name= which I believe is what jconsole uses to display the beans. It may be that you have two beans that basically have a null name and they are overwriting each other. It may be using the object's class as the name.

new ObjectName("org.javalobby.tnt.jmx:name=ApplicationCacheMBean1");
new ObjectName("org.javalobby.tnt.jmx:name=ApplicationCacheMBean2");

If you pull it up in Jconsole and click on the bean name, it should show the ObjectName that it is using. You might see an inferred name there.

As an aside, my SimpleJMX package forces problem creation of the ObjectName:

@JmxResource(domainName = "j256", beanName = "LookupCache")
public class LookupCache {

This creates the ObjectName: j256:name=LookupCache

Gray
  • 115,027
  • 24
  • 293
  • 354