try {String DOMAIN = ' localhost ';//Create a mbeanserver mbeanserver server = mbeanserverfactory.creatembeanserver (domain); /The Mbeanserver registration Loginstatsmbean//Mbeanserver.registermbean (Object,objectname) method uses two parameters: one is an example 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 () for jmxconnectorserver jmxconnectorserver jmxserver = Jmxconnectorserverfactory.newjmxconnectorserver (URL, null, server); System.out.println (URL); Register Locateregistry.createregistry (1099) on RMI; Jmxserver.start (); catch (Exception e) {e.printstacktrace ();}
The public method within this Mbean can be accessed via 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 registered to.