Getting Started with JMX Monitoring in NetBeans IDE

The NetBeans JMX Module integrates JMX technology right into your workflow in the NetBeans IDE. This module allows you to quickly develop management applications, add management to existing applications, develop manager applications, and monitor the state of the Virtual Machine.

This document has been updated for the JMX Wizard module version 3.0, for NetBeans IDE 6.5 and newer, and running on top of JDK 6 or JDK 7. You can download the JMX module from the Update Center.

Note: This document is a short and quick introduction to the JMX module for NetBeans IDE. For more detailed information, complete the JMX Module Tutorial Adding JMX Instrumentation to a Java Application.

This getting started document gives you an overview of the JMX module features:

Content on this page applies to NetBeans IDE 7.0, 7.1, 7.2 and 7.3


This tutorial assumes you have some basic knowledge of, or programming experience with, the following technologies.

You will also benefit from having some knowledge on Monitoring and Management for the Java Platform

Software Needed for the Tutorial

For this tutorial you need to have the following software installed on your computer:

Software or Resource Version Required
NetBeans IDE 7.0, 7.1, 7.2, 7.3, Java bundle
Java Development Kit (JDK) version 6 or 7
JMX plugin Available from NetBeans Update Center
JConsole plugin Available from NetBeans Update Center

To install the JMX and JConsole plugins, choose Tools > Plugins and download the modules from the NetBeans Update Center.

Accessing the JMX Wizards

After you have installed the JMX plugin and your project is open, you can access the JMX wizard by choose File > New File (Ctrl-N) and selecting the JMX category. You can then choose among the following:

Updating MBeans

You can add attributes and operations to your MBeans with the JMX contextual menu actions, which will popup a dialog box. You can also have your MBeans implement the NotificationEmitter interface.

To update an MBean, either select the MBean class Java file in the Project tree and access the JMX popup menu by right-clicking on the node, or simply right-click in the editor's window where your MBean class Java file is opened and access the JMX popup menu.

These actions are demonstrated in Exercise 3 of the Adding JMX Instrumentation to a Java Application tutorial.

Registering MBeans

To remotely connect to your MBeans and manage your application, your MBeans need to be registered into an MBean Server.

An MBean Server is the main central piece of the JMX technology. It keeps reference of all MBean registered into it, can send notifications of new MBean registration or deletion, and can accept remote connections to expose attributes and operations of its registered MBeans. If you are not familiar with MBean Server role, read the API documentation.

Starting with JDK 5, the Java Platform provides a default MBean Server, called the Platform MBean Server. It enables you to monitor the JVM, but you can also use it to register your own MBeans into it. For details on the Java Platform MBean Server, read the API documentation.

Depending on its logic, determine where in your application code you want your MBeans to be registered, typically in the initialization phase of your Main class. Right-Click in your editor's window at the location where you want the MBean's registration code to be generated, select the JMX submenu and then the "Generate MBean Registration..." action.

This action is demonstrated in Exercise 5 of the Adding JMX Instrumentation to a Java Application tutorial.

Implementing and Executing Manageable Applications

JConsole is a JMX-compliant graphical tool for monitoring a Java virtual machine. JConsole can monitor both local and remote JVMs and can be used to monitor and manage JMX applications.

Typically, the work flow of implementing and executing manageable applications is as follows:

  1. Generate your MBeans.
  2. Add implementation to your MBeans
  3. Generate MBean's registration code.
  4. Run or debug your project with JConsole.

After you install the JMX and JConsole plugins you will see that the following buttons are added to the toolbar. The actions are also accessible under the Debug menu item in the main menu.

Button Description
Run Main Project with Monitoring and Management button in the toolbar Run Main Project with Monitoring and Management
Debug Main Project with Monitoring and Management button in the toolbar Debug Main Project with Monitoring and Management
Start JConsole Management Console button in the toolbar Start JConsole Management Console

Note. JConsole is part of the Java Platform and can be used independently from the IDE. For details, refer to the following resources.

Running the Sample Application

The JMX module includes a sample application with JMX monitoring built into it.

  1. Choose File > New Project.
  2. In Samples, select the JMX category.
  3. Select the Anagram Game Managed with JMX project.
    screenshot of Anagram Game Managed with JMX project in New Project wizard
  4. Click Next. There is no need to change the supplied default project name or location values. Make sure the Set as Main Project checkbox is selected and click Finish.
  5. Once your project is created, and set as the Main Project, Run it with JConsole by clicking the "Run Main Project with Monitoring and Management" JConsole button.

    Clicking this button launches and displays the Anagram Game:

    Anagram Game

    The JConsole window is also displayed.

  6. In the JConsole window, select the MBeans tab and in the tree layout on the left open down all nodes under as shown below.
    screenshot of JConsole window
  7. Select the Notifications node and click on the Subscribe button at the bottom so that JConsole will receive a new notification each time an anagram is solved.
  8. Now go to the Anagrams Game window, and solve the first three or four anagrams (The answers are in the WordLibrary class, but here they are: abstraction, ambiguous, arithmetic, backslash, ...)
  9. Go back to JConsole, and notice that it received the four notifications.
  10. Click on the Attributes node and notice the attributes values are updated:
    screenshot of JConsole window showing updated values
Send Feedback on This Tutorial

See Also

This document was a short and quick introduction to the JMX module for NetBeans IDE. For more detailed information, see the following JMX module tutorial: