aspose file tools
The moose likes Distributed Java and the fly likes JMX: registerMBean Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Distributed Java
Reply Bookmark "JMX: registerMBean" Watch "JMX: registerMBean" New topic
Author

JMX: registerMBean

Ann Carpentier
Greenhorn

Joined: Sep 22, 2004
Posts: 5
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
Sheriff

Joined: Sep 28, 2004
Posts: 16815
    
  19

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Alan Hermin
Ranch Hand

Joined: Feb 16, 2006
Posts: 290
Can someone tell me what is the Java Managment Extension(JMX)?and wh its use?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: JMX: registerMBean
 
Similar Threads
How to get MBeanServer from Servlet?
Suspending/Pausing a MDB's Consumption Programmatically
Servlet access to MBean in JBoss
How to reference a JMX MBean ?
Accessing application-level default work manager