Manage Learn to apply best practices and optimize your operations.

Making MBean work

In part four, learn how to ensure that MBean interface has been accurately implemented.

In the first three parts of this tutorial, I discussed how to create a generic application MBean that can be used across all your Web applications. Now that we have the MBean application built and deployed to an application server (Glassfish 3.1 in our case), VisualVM can be used to view it. Below is a screenshot showing the com.lynden.JmxDemoWebProject MBean that was previously created. We can see the attributes that were defined in the MBean interface on the right portion of the UI, including the app start date, the build date, properties and version.

GlassFish app server 1
Figure 1. Viewing the MBean application

Clicking on the Operations tab exposes a button to call the refreshProperties() method that was defined in the MBean interface.

GlassFish app server 2
Figure 2. MBean interface view

As an experiment, I edited the JmxDemoWebProjects property file and changed the version number of the application to 1.0.1-SNAPSHOT. To see if the MBean is working as advertised, I click the refreshProperties button, and then go back to the Attributes tab. As shown in Figure 3, the applications version number has been updated from 1.0.0 to 1.0.1-SNAPSHOT.

GlassFish app server 3
Figure 3. Updated applications version

JMX and VisualVM has given us the ability to monitor our Web applications in real-time. Using Spring we have been able to create a baseline MBean that all of our Web applications can use to provide a common set of information about the applications, without adding much overhead to the applications development.

In the next post, I will write about how applications can take the base ApplicationMBean interface and Application MBean class and extend them so that specific applications expose additional attributes or methods via JMX.

More on this tutorial:
Monitor your Web applications using JMX and Spring

Configure VisualVM to connect to the app server

Dig Deeper on Spring framework