Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMX: registerMBean

 
Ann Carpentier
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm having troubles with JMX. In the code below, you see how I register an MBean.
The problem is, that from everywhere in my application, I call this particular code, and I give as return-value my oltbMBean. I have the feeling, that I'm working with different MBeans, each time I call the code below. The result is, that my values have the initial value...



I suppose you only have to register, a specific MBean, just one time. Is it possible to find the 'registered' MBean?
I know I'm missing something, but I don't know what...


Can anyone help me? It's very urgent...

Thanks in advance,
Ann Carpentier
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is, that from everywhere in my application, I call this particular code, and I give as return-value my oltbMBean. I have the feeling, that I'm working with different MBeans, each time I call the code below. The result is, that my values have the initial value...


Yes, this code will create a new instance and register it with the MBean Server. So, if you call the code again, you will get a new MBean registered.

I suppose you only have to register, a specific MBean, just one time. Is it possible to find the 'registered' MBean?
I know I'm missing something, but I don't know what...


More commonly, the registerMBean() method is not available -- since most of the time, application work through a connector, instead of the MBean server directly. The reason that you can is because you are running in the same JVM as the MBean server. This trick will not work if you are connecting with JNDI via a different JVM.

Anyway, since you are in the same JVM, just register it once, and store the MBean somewhere in a globally accessable reference. The next time you need the MBean, just return the previously instantiated reference.

Henry
 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me what is the Java Managment Extension(JMX)?and wh its use?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic