Digital Edition

Frank's Java Code Stack #11 - Managing Resources with Mbeans
Frank's Java Code Stack #11 - Managing Resources with Mbeans

(March 17, 2003) - I got introduced to MBeans very lately, when I was working with some J2EE applications. At first I thought using MBeans was just another way of remotely managing the server side components. But when I started using it more extensively in my applications, I found that monitoring and managing my application became easier and remote controlling my bean attributes became a breeze. Most of you must be already aware of Java Management Extensions (JMX), a framework for monitoring and managing resources. Each manageable resource is called an MBean (The resource can either be a device or a JMX aware application). Unfortunately JMX is not part of JDK 1.4 and it might ship with J2EE 1.4 later this year. For now, let us create a simple application and manage it remotely using MBeans.

Our interface, which exposes different operations, which can be managed by MBeans, looks like:

public interface JDJMBean {
public int getX();
public void setX(int x);
public int getY();
public void setY(int y);
public int getZ();

Our simple application accepts two integers from an MBean controlled client and returns the summation. Note that we are defining attributes x and y as RW (Read-Write) and z as RO (Read only).

Now let us implement this interface in our application:

public class JDJ implements JDJMBean {
private int x,y,z;
public int getX() {
return x;
public int getY() {
return y;
public void setX(int x){
this.x = x;
public void setY(int y){
this.y = y;
public int getZ() {
return (x+y);

Now we need to start an MBean Server and make it communicate with our MBean. The communication takes place through 'Agents', which are the single point of communication from the remote client.

import com.sun.jdmk.comm.*;

public class JDJAgent {
public static void main(String args[]) {

/* Starting the Mbean server */
MBeanServer mbs =

/* Starting the HTML Adaptor Server
for managing resources through web */
HtmlAdaptorServer has =
new HtmlAdaptorServer();
JDJMBean jdj = new JDJ();

try {

/* Registering our MBean with the
server */
ObjectName on1 = new ObjectName(
mbs.registerMBean(jdj, on1);

ObjectName on2 = new ObjectName(

/* Setting port for our http Listener */

/* Registering the HTML Adaptor
with the MBean server */
mbs.registerMBean(has, on2);

/* Start the server */

}catch(Exception e){System.out.println(""+e);}

Once you have compiled all the three classes, start the MBean Agent, using $ java JDJAgent

Now open a Web browser window and connect to

From there you can modify the bean attributes - remotely! For working with MBeans we need jmxri.jar (Comes with JMX Reference Implementation). Since we have used HTML Adaptor server for Web-based management, we also need jmxtools.jar (also part of JMX). For more information, check out

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

To access MBean Server from within the same VM, simply look up java:comp/MBeanServer, as:
javax.naming.InitialContext ic = new javax.naming.InitialContext(); mbeanServer =

MBean can also be instantiated and registered remotely by code in a Java Dynamic Management Kit client.
Regardless of the registration operation, the MBean server generates a notification whenever an MBean is registered. The information sent with the notification includes the object name of the new MBean.

Use DynamicMBeans
DynamicMbeans instrumentation can be used to quickly make an existing resource manageable. The implementation of the DynamicMBean interface can provide an instrumentation wrapper for an existing resource. check out how you can can do it from

The above code works for me. But is there a way through which I can register the Bean from a remote client? I think currently the managable MBean class must lie in server classpath.

Is there a way that I can even do the register from remote client?

>But where are all the HTML pages
>coming from? Are those pages & tables
>all generated dynamically from the JMX
>jar files?

See for example

it is a generic JMX adaptor implemented as a set of custom tags driven JSP pages

No wonder people are excited about MBeans and JMX! I've been looking for a quick way intro to JMX and this was perfect.

But where are all the HTML pages coming from? Are those pages & tables all generated dynamically from the JMX jar files? And what does that stuff mean, MBeanServerDelegate, HtmlAdaptor?? I can kind of guess at a lot of stuff, but how about a few more paragraphs about what we're seeing? And maybe some hints about how to include MBeans into our current projects.



When you use the same code from the stack, make sure you use the same class name as file name. In case if u change the class name make sure that it sticks to the specified nomenclature.
we have implemented JDJMBean in the class JDJ. Make sure that u follow the same naming convention.
(i.e) class Test implements TestMBean
The code works fine.

Error message:
" MBeanTeste does not implement the MBeanTesteMBean interface or the DynamicMBean interface"
using - jmx 1.2 ri

Subscribe to the World's Most Powerful Newsletters


DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held Novemb...
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO an...
DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, ...
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing w...
@DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held Novem...
DXWorldEXPO LLC announced today that Dez Blanchfield joined the faculty of CloudEXPO's "10-Year Anni...
"We started a Master of Science in business analytics - that's the hot topic. We serve the business ...
The standardization of container runtimes and images has sparked the creation of an almost overwhelm...
As DevOps methodologies expand their reach across the enterprise, organizations face the daunting ch...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As au...
The best way to leverage your Cloud Expo presence as a sponsor and exhibitor is to plan your news an...
As you move to the cloud, your network should be efficient, secure, and easy to manage. An enterpris...
There is a huge demand for responsive, real-time mobile and web experiences, but current architectur...
DXWorldEXPO LLC announced today that "Miami Blockchain Event by FinTechEXPO" has announced that its ...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will ...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to ...
"NetApp is known as a data management leader but we do a lot more than just data management on-prem ...
We call it DevOps but much of the time there’s a lot more discussion about the needs and concerns of...
The dynamic nature of the cloud means that change is a constant when it comes to modern cloud-based ...
"Since we launched LinuxONE we learned a lot from our customers. More than anything what they respon...