1 Overview of Java SE Monitoring and Management

This topic introduces the features and utilities that provide monitoring and management services to the Java Platform, Standard Edition (Java SE platform).

Key Monitoring and Management Features

The Java SE platform includes significant monitoring and management features. These features fall into four broad categories:

Java Virtual Machine Instrumentation

The Java Virtual Machine (Java VM) is instrumented for monitoring and management, enabling built-in (or ready-to-use) management capabilities that can be accessed both remotely and locally.

See Monitoring and Management Using JMX Technology.

The Java VM includes a platform MBean server and platform MBeans for use by management applications that conform to the Java Management Extensions (JMX) specification. These platforms are implementations of the monitoring and management API. The platform MXBeans and MBean servers are introduced in the Platform MXBeans and Platform MBean Server topics.

Monitoring and Management API

Java SE includes the following APIs for monitoring and management:

  • java.lang.management: Enables monitoring and managing the Java virtual machine and the underlying operating system. The API enables applications to monitor themselves, and enables JMX-compliant tools to monitor and manage a virtual machine locally and remotely. This API provides access to the following types of information:
    • Number of classes loaded and threads running

    • Java VM uptime, system properties, and VM input arguments

    • Thread state, thread contention statistics, and stack trace of live threads

    • Memory consumption

    • Garbage collection statistics

    • Low memory detection

    • On-demand deadlock detection

    • Operating system information

  • Attach: Allows a management agent to be dynamically loaded onto a virtual machine.

  • JConsole: Provides a programmatic interface to access JConsole such as adding a JConsole plug-in.

Monitoring and Management Tools

The Java SE platform provides a graphical monitoring tool called JConsole. JConsole implements the JMX API, and enables you to monitor the performance of a Java VM and any instrumented applications. It provides information to help you optimize the performance.

Some of the enhancements in JConsole are as follows:

  • JConsole plug-in support, which allows you to build your own plug-ins to run with JConsole. For example, you can add a custom tab for accessing the MBeans of the application.

  • Dynamic attach capability allowing you to connect JConsole to any application that supports the Attach API.

  • Enhanced user interface, which makes data more easily accessible.

  • New Overview and VM Summary tabs for a better presentation of general information about your Java VM.

  • HotSpot Diagnostic MBean, which provides an API to request heap dump at runtime and also change the setting of certain VM options.

  • Improved presentation of MBeans to make it easier to access the MBeans operations and attributes.

JConsole is presented in detail in the Using JConsole topic.

Other command-line tools are also supplied with the Java SE platform.

Java Management Extensions Technology

The Java SE platform, release 11 includes the Java Management Extensions (JMX) specification, version 1.4. The JMX API allows you to instrument applications for monitoring and management. A remote method invocation (RMI) connector allows this instrumentation to be remotely accessible, for example, using JConsole.

See JMX technology documentation in the Java Platform, Standard Edition Java Management Extensions Guide.

The following sections provide a brief introduction to the main components of the JMX API.

What Are MBeans?

JMX technology MBeans are managed beans, namely Java objects that represent resources to be managed. An MBean has a management interface consisting of the following:

  • Named and typed attributes that can be read and written.

  • Named and typed operations that can be invoked.

  • Typed notifications that can be emitted by the MBean.

For example, an MBean representing an application's configuration can have attributes representing different configuration parameters, such as a CacheSize. Reading the CacheSize attribute will return the current size of the cache. Writing CacheSize updates the size of the cache, potentially changing the behavior of the running application. An operation such as save stores the current configuration persistently. The MBean can send a notification such as ConfigurationChangedNotification when the configuration changes.

MBeans can be standard or dynamic. Standard MBeans are Java objects that conform to design patterns derived from the JavaBeans component model. Dynamic MBeans define their management interface at runtime. An additional type of MBean, called MXBean, is added to the Java platform.

  • A standard MBean exposes the resource to be managed directly through its attributes and operations. Attributes are exposed through getter and setter methods. Operations are the other methods of the class that are available to managers. All these methods are defined statically in the MBean interface and are visible to a JMX agent through introspection. This method is the most straightforward way of making a new resource manageable.

  • A dynamic MBean is an MBean that defines its management interface at runtime. For example, a configuration MBean determines the names and types of the attributes that it exposes, by parsing an XML file.

  • An MXBean is a type of MBean that provides a simple way to code an MBean that references only a predefined set of types. In this way, you can ensure that the MBean is usable by any client. It includes remote clients without any requirement that the client has access to model-specific classes, which represents the types of your MBeans. The platform MBeans are all MXBeans.

MBean Server

To be useful, an MBean must be registered in an MBean server. An MBean server is a repository of MBeans. Each MBean is registered with a unique name within the MBean server. Usually the only access to the MBeans is through the MBean server. In other words, code does not access an MBean directly, but rather accesses the MBean by the name through the MBean server.

The Java SE platform includes a built-in platform MBean server. See Using the Platform MBean Server and Platform MXBeans.

Creating and Registering MBeans

There are two ways to create an MBean. One is to construct a Java object that will be the MBean, then use the registerMBean method to register it in the MBean server. The other method is to create and register the MBean in a single operation using one of the createMBean methods.

The registerMBean method is simpler for local use, but cannot be used remotely. The createMBean method can be used remotely, but sometimes requires attention to the class loading issues. An MBean can perform actions when it is registered in or unregistered from an MBean server if it implements the MBeanRegistration interface.

Instrumenting Applications

General instructions on how to instrument your applications for management by the JMX API is beyond the scope of this document.

Platform MXBeans

A platform MXBean is an MBean for monitoring and managing the Java VM, and other components of the Java Runtime Environment (JRE). Each MXBean encapsulates a part of VM functionality such as the class loading system, just-in-time (JIT) compilation system, garbage collector, and so on.

Table 1-1 lists all the platform MXBeans and the aspect of the VM that they manage. Each platform MXBean has a unique javax.management.ObjectName for registration in the platform MBean server. A Java VM may have zero, one, or more than one instance of each MXBean, depending on its function, as shown in the table.

Table 1-1 Platform MXBeans

Interface Part of VM Managed Object Name Instances per VM

ClassLoadingMXBean

Class loading system

java.lang:type= ClassLoading

One

CompilationMXBean

Compilation system

java.lang:type= Compilation

Zero or one

GarbageCollectorMXBean

Garbage collector

java.lang:type= GarbageCollector, name=collectorName

One or more

LoggingMXBean

Logging system

java.util.logging:type =Logging

One

MemoryManagerMXBean (subinterface of GarbageCollectorMXBean)

Memory pool

java.lang: typeMemoryManager, name=managerName

One or more

MemoryPoolMXBean

Memory

java.lang: type= MemoryPool, name=poolName

One or more

MemoryMXBean

Memory system

java.lang:type= Memory

One

OperatingSystemMXBean

Underlying operating system

java.lang:type= OperatingSystem

One

RuntimeMXBean

Runtime system

java.lang:type= Runtime

One

ThreadMXBean

Thread system

java.lang:type= Threading

One

The details on platform MXBeans (apart from LoggingMXBean) are described in the java.lang.management API reference. The LoggingMXBean interface is described in the java.util.logging API reference.

Platform MBean Server

The platform MBean server can be shared by different managed components running within the same Java VM. You can access the platform MBean server with the method ManagementFactory.getPlatformMBeanServer(). The first call to this method creates the platform MBean server and registers the platform MXBeans using their unique object names. Subsequently, this method returns the initially created platform MBeanServer instance.

MXBeans that are created and destroyed dynamically (for example, memory pools and managers) will automatically be registered and unregistered in the platform MBean server. If the system property javax.management.builder.initial is set, then the platform MBean server will be created by the specified MBeanServerBuilder parameter.

You can use the platform MBean server to register other MBeans besides the platform MXBeans. This enables all MBeans to be published through the same MBean server, and makes network publishing and discovery easier.