JMX - Standard MBean

Java Conceptuel Diagram

Example

From Java Management Extensions (JMX) (API, Tutorial)

package Jmx;

import java.lang.management.*;
import javax.management.*;

public static void main(String[] args) throws Exception {

        // A JMX Agent is just a process that starts a MBean Server.
        // Getting the server
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        // Construct an (JMX) object name from the given string.
        // com.example is the directory path to the MBean in the MBean explorer
        ObjectName name = new ObjectName("com.example:type=Hello");

        // Register it
        Hello mbean = new Hello();
        mbs.registerMBean(mbean, name);

        // And the process never end
        System.out.println("Waiting forever...");
        Thread.sleep(Long.MAX_VALUE);

    }
  • Run it
  • Open Jconsole (jdk/bin/jconsole) and choose your class name

Jconsole New Connection Jmxhello

  • In the Mbean tab, you can see the MBean below the com.example node

Jconsole Mbean Hello





Discover More
Java Conceptuel Diagram
JMX - Getting Started

From Java Management Extensions (JMX) (API, Tutorial) See Standard MBean Example Sample: jdk\sample\jmx\jmx-scandir
Java Conceptuel Diagram
JMX - Mbean (Managed Bean|Manageable resource)

A managed bean (MBean) is a Java object that represents a JMX manageable resource in a distributed environment, such as: an application, a service, a component or a device. An MBean is a namedmanaged...



Share this page:
Follow us:
Task Runner