Application Monitoring with JConsole

January 31, 2007


Hidden in the bin directory of the JDK distribution are some little known, but useful tools. In this article we’ll look at the basics of using jconsole to monitor threads, memory usage and object creation.

Setting Your App Up to Be Monitored

If you’re running Java 6, you’re all good to go. The option to allow your application to be monitored is on by default. Skip to the section entitled Launching JConsole and collect 100 points for being on the cutting edge.

If you’re on Java 1.42 or earlier, do not pass go, or collect $200. Time to upgrade. JConsole requires Java 5 or later.

If you’re on Java 5, then you need to start the application that you want to monitor while passing an extra flag to the JVM to enable monitoring. For our example we’re going to launch the SwingSet demo that comes with the JDK. If you’re on Windows, Linux or Solaris it’s usually located in %JDK_HOME%/demo/jfc/SwingSet2. If you’re on Mac OS X, it’s usually in /Developer/Examples/Java/JFC/SwingSet2.

Launching the Application to be Monitored

If you’re launching the application from the command line, simply add -Dcom.sun.management.jmxremote=true right after the java command. Like this:

java -Dcom.sun.management.jmxremote=true -jar SwingSet2.jar

If you’re launching the application from within Eclipse, select Run -> Run…, click on the Arguments tab and specify -Dcom.sun.management.jmxremote=true in the VM arguments field.

If you’re launching the application from within NetBeans, select the Project, right-click and select Properties, select Run node and specify -Dcom.sun.management.jmxremote=true in the VM Options field.

Launching JConsole

JConsole comes with the JDK (not the JRE) and can be found in %JDK_HOME%/bin on Windows, Solaris and Linux and in /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands on Mac OS X. To launch it, open a terminal or command window, change to the directory containing it and execute jconsole. This should open a window that looks like this:

Jconsole Start

Click the Connect button to begin monitoring your app. As you can see from the screenshots below you can can view summary information, threads usage, memory usage, current and total classes loaded.

Jconsole Summary

Jconsole Threads

Jconsole Memory

Jconsole Classes

The information provided by jconsole is invaluable when tracking down thread creep or memory leaks. It works great to monitor an app while putting it through its paces or when leaving it to run over the weekend to ensure there aren’t any uphill graphs. It’s easy, free and doesn’t require any extra work during application development.

Joshua Smith

Technorati Tags: , , , ,



  1. Thanks for information.
    many interesting things

  2. Hi,

    I am trying to monitor one of my application which is running on Tomcat.

    I have modified catalina.sh

    CATALINA_OPTS=”$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false”
    CATALINA_OPTS=”$CATALINA_OPTS -Dcom.sun.management.jmxremote.authenticate=false”

    When i navigated to the JDK directory in Solaris and tried to run Jconsole

    It says command not found?

    Can you please help me?

  3. Try prepending the command with a dot and a slash.

    Change to the directory.
    Type: ./jconsole

    This is probably because . (the current directory) is not in your PATH.


  4. Thanks. nice article. helped me to find out potential memory leaks.

  5. i run my application from netbeans and wet up VM options as you described here, but jconsole is not displayed when my app launches ? is there some other setting that i am missing????

  6. I like the helpful info you provide in your articles.
    I will bookmark your blog and check again here regularly.
    I am quite certain I will learn lots of new stuff right here!

    Good luck for the next!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: