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


Now is the time for a truly global DX event, to bring together the leading minds from the technology...
On-premise or off, you have powerful tools available to maximize the value of your infrastructure an...
Atmosera delivers modern cloud services that maximize the advantages of cloud-based infrastructures....
Artifex Software began 25-years ago with Ghostscript, a page description language (PDL) interpreter ...
In an age of borderless networks, security for the cloud and security for the corporate network can ...
In today's always-on world, customer expectations have changed. Competitive differentiation is deliv...
As the digitization of business accelerates the move of critical applications and content to the clo...
Blockchain has shifted from hype to reality across many industries including Financial Services, Sup...
Cloud Storage 2.0 has brought many innovations, including the availability of cloud storage services...
Concerns about security, downtime and latency, budgets, and general unfamiliarity with cloud technol...
In very short order, the term "Blockchain" has lost an incredible amount of meaning. With too many j...
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web...
For enterprises to maintain business competitiveness in the digital economy, IT modernization is req...
Cloud-Native thinking and Serverless Computing are now the norm in financial services, manufacturing...
Data center, on-premise, public-cloud, private-cloud, multi-cloud, hybrid-cloud, IoT, AI, edge, SaaS...
Public clouds dominate IT conversations but the next phase of cloud evolutions are "multi" hybrid cl...
Moving to Azure is the path to digital transformation, but not every journey is effective. Organizat...
Most modern computer languages embed a lot of metadata in their application. We show how this goldmi...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with exp...
Every organization is facing their own Digital Transformation as they attempt to stay ahead of the c...