Monitor your Java on Linux with jconsole | Opensource.com

Monitor your Java on Linux with jconsole

How to use the Java monitoring and management console included in the Java Development Kit.

Puzzle pieces coming together to form a computer screen
Image by : 

Opensource.com

x

Subscribe now

Get the highlights in your inbox every week.

The Java Development Kit (JDK) provides binaries, tools, and compilers for the development of Java applications. One helpful tool included is jconsole.

To demonstrate, I will use the WildFly J2EE application server, which is part of the JBOSS open source application server project. First, I start up a standalone instance.

~/wildfly/24.0.1/bin$ ./standalone.sh
=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /home/alan/wildfly/24.0.1

  JAVA: /usr/lib/jvm/java-11-openjdk-11.0.11.0.9-5.fc34.x86_64/bin/java

Now, in another terminal, I type jconsole.

$ jconsole

Upon launching, jconsole lists local instances. Select Local Process, then select the name of the process and click Connect. That is all it takes to connect and begin using jconsole with a running Java Virtual Machine (JVM).

Overview

The Java Monitoring and Management Console shows the process identifier (PID) at the top of the dashboard. The Overview tab has four graphs to show the vitals for Heap Memory Usage, Threads, Classes, and CPU Usage.

The tabs along the top provide more detailed views of each area.

Memory

The Memory tab displays graphs of various aspects of the memory being used by the JVM. The amount of the server system memory allocated to the JVM is called the heap. This screen also provides details about usage by the internal components of the heap, such as the Eden Space, Old Gen, and the Survivor Space. You can manually request a garbage collection action as well.

jconsole_tab_memory.png

jconsole memory tab

(Alan Formy-Duvall, CC BY-SA 4.0)

Threads

The Threads tab shows how many threads are running. You can also manually check for deadlocks.

jconsole_tab_threads.png

jconsole thread dashboard showing number of threads over time and a scrolling list of threads

(Alan Formy-Duvall, CC BY-SA 4.0)

Classes

The classes tab tells you how many classes are loaded and how many have been unloaded.

jconsole_tab_classes.png

jconsole classes tab showing number of loaded classes over time

(Alan Formy-Duvall, CC BY-SA 4.0)

VM Summary

The VM Summary tab provides many details about the application and the host system. You can learn which operating system and architecture you are on, the total amount of system memory, the number of CPUs, and even swap space.

Further details about the JVM shown in the summary include current and maximum heap size and information about the garbage collectors in use. The bottom pane lists all of the arguments passed to the JVM.

MBeans

The last tab, MBeans, lets you drill down through all of the MBeans to view attributes and values for each.

jconsole_tab_mbeans.png

MBeans tab

(Alan Formy-Duvall, CC BY-SA 4.0)

Conclusion

Java has been around a long time, and it continues to power millions of systems worldwide. Plenty of development environments and monitoring systems are available, but having a tool like jconsole included in the base kit can be highly valuable.

Person drinking a hot drink at the computer

Implement persistent settings when you're writing software in Java.
Learning and studying technology is the key to success

Java is powerful, diverse, scalable, and fun. Here's why—and how—you should be using it.
Coding on a computer

WildFly is a popular choice for developers who want to develop enterprise-ready applications.

Topics

About the author

Alan
Alan Formy-Duval - Alan has 20 years of IT experience, mostly in the Government and Financial sectors. He started as a Value Added Reseller before moving into Systems Engineering. Alan's background is in high-availability clustered apps. He wrote the 'Users and Groups' and 'Apache and the Web Stack' chapters in the Oracle Press/McGraw Hill 'Oracle Solaris 11 System Administration' book. He earned his Master of Science in Information Systems from George Mason University. Alan is a long-time proponent of Open...