Skip to content

Instantly share code, notes, and snippets.

@cleantutorials
Created May 19, 2020 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleantutorials/325e1d8bd4ed5e58fd256e8ea64d023a to your computer and use it in GitHub Desktop.
Save cleantutorials/325e1d8bd4ed5e58fd256e8ea64d023a to your computer and use it in GitHub Desktop.
RegisterMyMBean.java
package com.cleantutorials.jconsole.jmx;
import java.lang.management.ManagementFactory;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
public class RegisterMyMBean {
public static void main(String[] args) throws MalformedObjectNameException,
InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException {
MBeanServer server = ManagementFactory.getPlatformMBeanServer(); // Get the MBean Server instance.
ObjectName name = new ObjectName("JMXTutorialMBean:type=JMXTutorial"); // Create a unique Object Name.
JMXTutorial tutorial = new JMXTutorial();
server.registerMBean(tutorial, name); // Register the MBean with the MBean Server.
try {
Thread.sleep(360000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment