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


Technological progress can be expressed as layers of abstraction - higher layers are built on top of...
"Calligo is a cloud service provider with data privacy at the heart of what we do. We are a typical ...
Having been in the web hosting industry since 2002, dhosting has gained a great deal of experience w...
NanoVMs is the only production ready unikernel infrastructure solution on the market today. Unikerne...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO Silicon Valley 2019 will cover all of these tools, with the m...
SUSE is a German-based, multinational, open-source software company that develops and sells Linux pr...
Your job is mostly boring. Many of the IT operations tasks you perform on a day-to-day basis are rep...
When building large, cloud-based applications that operate at a high scale, it’s important to mainta...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, disc...
Big Switch's mission is to disrupt the status quo of networking with order of magnitude improvements...
Lori MacVittie is a subject matter expert on emerging technology responsible for outbound evangelism...
Dynatrace is an application performance management software company with products for the informatio...
In his session at 21st Cloud Expo, Michael Burley, a Senior Business Development Executive in IT Ser...
All in Mobile is a mobile app agency that helps enterprise companies and next generation startups bu...
Yottabyte is a software-defined data center (SDDC) company headquartered in Bloomfield Township, Oak...
Serveless Architectures brings the ability to independently scale, deploy and heal based on workload...
Whenever a new technology hits the high points of hype, everyone starts talking about it like it wil...
Every organization is facing their own Digital Transformation as they attempt to stay ahead of the c...
Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (No...
Chris Matthieu is the President & CEO of Computes, inc. He brings 30 years of experience in developm...