JMX - Standard MBean

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

_

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

_


Powered by ComboStrap