Geertjan is a DZone Zone Leader and has posted 459 posts at DZone. You can read more from them at their website. View Full User Profile

Spring Rich Clients with JMX and Java VisualVM

  • submit to reddit

Creating a VisualVM Plugin for the Simple Spring Demo

In this section, we'll create a plugin that modifies VisualVM in such a way that it will recognize our Spring demo application.

The way in which VisualVM recognizes an application is via its main class.

When VisualVM is running and an application starts up with the main class specified by our plugin, VisualVM will provide an icon and a display name specifically for our application, together with subnodes for each of the attributes we've made available via our Spring-driven JMX bean.

We'll start all of this via a template that is part of the VisualVM Sample Collection 1.0. So go to the sample collection's page, download it, and install it into NetBeans IDE 6.1.

  1. Open the New Project wizard in the IDE and choose the "Explorer Subnodes" sample, which we'll use as our template:


  3. Once you've completed the wizard, you'll have a project with error messages because you haven't set the plugin's platform. The platform provides all the modules that provide the APIs used by the plugin. Now that VisualVM is part of the JDK, it's simple to get the necessary platform:


  4. Now that you've registered your platform, set VisualVM as the platform for the plugin you're working on:


  5. Now we're going to perform some small tweaks that will customize the template to our needs. After all, instead of the Anagram Game application, for which it was made, it should now be tailored to work with the Spring demo application. Optionally, you could refactor all the class names so that "Anagram" isn't referred to anymore. But let's do the essentials only:


    • Open org.visualvm.demoapplicationtype.applicationtype.AnagramApplicationTypeFactory. In this class the "createApplicationTypeFor" method specifies which application will be handled by our plugin. That, in turn, is determined by the main class of the application, which in our case is "app.SimpleApp" (assuming you're working with the Spring demo that comes with the Spring RCP Tooling plugin from the NetBeans Plugin Portal). So change that method and ensure that the application's main class is referred to in line 3 below:
      public ApplicationType createApplicationTypeFor(Application app, Jvm jvm, String mainClass) {
      if ("app.SimpleApp".equals(mainClass)) {
      return new AnagramApplicationType(app.getPid());
      return null;


    • Open org.visualvm.demoapplicationtype.application.AnagramApplicationProvider. Here is where JMX-related information is set. In "DiscoveryTask.onSchedule", make sure the same object name as the object name you defined earlier in the "Contact" domain object is used, for connecting to the JMX server:
      ObjectName obj = new ObjectName("app.SimpleApp:type=SpringDemo");

    • Open org.visualvm.demoapplicationtype.applicationtype.AnagramApplicationType. In the "getName()" method, change the display name to "Spring Simple Demo" (or whatever you'd like to have displayed in the explorer view). That's also where you can change the icon, using the "getIcon" method.


  6. Install the plugin and run the Spring demo application. The application should now be recognized as being a distinct application, because the display name and icon should change to the values you specified above. If you install the MBeans plugin into VisualVM, you'll be able to view the JMX info. Whether you do so or not, you're able to expand the "Attributes" node in the explorer view and thereby see the attributes exposed by the application via JMX:


That's it. Without having needed to understand much about the source code, we've been able to adapt it in such a way that we now have a plugin that provides unique functionality for the Spring demo application.


Further reading:



figure-1.png75.51 KB
figure-3.png79.4 KB
figure-4.png51.23 KB
figure-5.png64.41 KB
figure-6.png98.37 KB
figure-2.png65.65 KB
figure-7.png105.27 KB
figure-8.png68.62 KB
figure-9.png87.33 KB
Published at DZone with permission of its author, Geertjan Wielenga.


Andrew McVeigh replied on Mon, 2008/07/21 - 4:13am

these articles have been very, very interesting for me. it's the first time i've seen the spring rcp described in a clear manner.

i think the overhead of describing the widget structures via XML seems high. however the flexibility is impressive. it's a shame they are re-jigging the whole framework just as it seems to have reached a level of maturity. i lost interest in it about 2 years ago when no activity seemed to be occurring.

thanks for the series geertjan.


Geertjan Wielenga replied on Mon, 2008/07/21 - 2:48pm

Andrew, thanks a lot, I really appreciate your comments on this! Get ready for more parts in this series, over the coming weeks.

Jeremiah Holder replied on Wed, 2008/09/17 - 5:48pm


 I'm new to Java developent and am drinking from the firehose to get up to speed.  I discoverd the VisualVM tool and wished to use it for performance monitoring of our applications.  However, one key feature that I do not see is the ability to capture the data and export it to .csv, html, or xml.  It appears I can only save the data in the proprietary file type.

Do you have any suggestions for how to customize the API's to allow export of data?

Thanks for any help you might offer.



Liezel Jane Jandayan replied on Mon, 2011/08/22 - 9:19pm

Programmers can also capture data about the JVM software and save the data to the local system, and then view the data later or share it with others. VisualVM is built on the NetBeans Platform, its architecture is modular and easy to extend with plugins.-Yochanan Berkowitz

Passion Lab replied on Sun, 2012/09/02 - 4:02pm

This will cause both of these properties to be included in the management interface as attributes, but the age attribute will be read-only." In other words, if you also annote the setters, then the attributes will be writable in Java VisualVM. Also read the "best term papers" about Notifications (section 20.7), which could also be implemented in the context of Spring Rich Clients.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.