try {String DOMAIN = "localhost";//Create a mbeanserver mbeanserver server = Mbeanserverfactory.creatembeanserver (DOMAIN); /with Mbeanserver Registration the Loginstatsmbean//Mbeanserver.registermbean (Object,objectname) method uses two parameters: one is an instance of an Mbean implementation The other is an object of type ObjectName-it is used to uniquely identify the Mbean Server.registermbean (New Status (), New ObjectName (DOMAIN + ": Name=statusbean") ); Url:jmxserviceurl URL to access the JMX service = new Jmxserviceurl ("RMI", "127.0.0.1", 9589, "/jndi/rmi://localhost:" + 1099 + "/app") ; Start () and stop () to start and stop jmxconnectorserver jmxconnectorserver jmxserver = Jmxconnectorserverfactory.newjmxconnectorserver (URL, null, server); System.out.println (URL); Register Locateregistry.createregistry (1099) on the RMI; Jmxserver.start (); } catch (Exception e) {e.printstacktrace ();}
The public method inside the Mbean can be accessed through Jconsole:
Enter the JMX service Url:service:jmx:rmi:///jndi/rmi://localhost:1099/app in the JMX URL
You can access the methods in the Mbean that you have registered to.