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


A valuable conference experience generates new contacts, sales leads, potential strategic partners a...
Containers and Kubernetes allow for code portability across on-premise VMs, bare metal, or multiple ...
Everyone wants the rainbow - reduced IT costs, scalability, continuity, flexibility, manageability, ...
SYS-CON Events announced today that Silicon India has been named “Media Sponsor” of SYS-CON's 21st I...
We are seeing a major migration of enterprises applications to the cloud. As cloud and business use ...
SYS-CON Events announced today that has been named “Media Sponsor” of SYS-CON's 22n...
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT...
DXWorldEXPO LLC announced today that "IoT Now" was named media sponsor of CloudEXPO | DXWorldEXPO 20...
Andi Mann, Chief Technology Advocate at Splunk, is an accomplished digital business executive with e...
Most DevOps journeys involve several phases of maturity. Research shows that the inflection point wh...
DXWorldEXPO LLC announced today that ICOHOLDER named "Media Sponsor" of Miami Blockchain Event by Fi...
Today, we have more data to manage than ever. We also have better algorithms that help us access our...
DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, ...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: D...
DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held Novemb...
CI/CD is conceptually straightforward, yet often technically intricate to implement since it require...
The now mainstream platform changes stemming from the first Internet boom brought many changes but d...
Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (No...
CloudEXPO New York 2018, colocated with DXWorldEXPO New York 2018 will be held November 11-13, 2018,...