This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes JMX: registerMBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
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: 18505
    
  40

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://aspose.com/file-tools
 
subject: JMX: registerMBean
 
Similar Threads
Accessing application-level default work manager
Servlet access to MBean in JBoss
How to get MBeanServer from Servlet?
How to reference a JMX MBean ?
Suspending/Pausing a MDB's Consumption Programmatically