javax.management.remote


1. Connect to a JMX Server

import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

class ConnectToJMXServer {
    public static void main(String[] args) throws Exception {
        // Server address and port
        String host = "localhost";
        int port = 9999;

        // JMX Service URL
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi");

        // Create a JMX Connector
        JMXConnector connector = JMXConnectorFactory.connect(url);

        // Get the MBean Server Connection
        javax.management.MBeanServerConnection mbsc = connector.getMBeanServerConnection();

        // Close the connector
        connector.close();
    }
}

2. Create a JMX Server

3. Invoke an Operation on a MBean

4. Get Attribute Value from MBean

5. Set Attribute Value in MBean

6. Add Notification Listener to MBean

7. Remove Notification Listener from MBean

**8. Query MBeans with Query Exp