JMX is a good choice for the ability to add monitoring to your project, mostly simple and versatile
First, create an interface named Specification: Java class name + "MBean" suffix
The Java class is then generated to implement the above interface, the Mbean class
Then, create the Mbeanserver, the JMX agent, to receive the client call
Then, instantiate the Mbean, generate objectname, register the Mbean in Mbeanserver
In order to access via browser, join Htmladaptor, register in Mbeanserver Htmladaptorserver
The sample code is as follows:
Public Interface Hellombean { String SayHello ();} Public class Implements Hellombean { @Override public String SayHello () { return Charset.defaultcharset (). Name (); }}
//mbeanserver mbs = Mbeanserverfactory.creatembeanserver ();//cannot be used in JconsoleMbeanserver mbs = Managementfactory.getplatformmbeanserver ();//can be used in Jconsole//Create an MbeanHellombean MB =NewHello ();//registering an mbean in MbeanserverMbs.registermbean (MB,NewObjectName ("Myappmbean:name=controller"));//create an adapter for the ability to access the Mbean through a browserHtmladaptorserver adapter =Newhtmladaptorserver (); Adapter.setport (9797); Mbs.registermbean (Adapter,NewObjectName ("myappmbean:name=htmladapter,port=9797") ; Adapter.start ();
Open http://127.0.0.1:9797/in the browser, you can see
Click "Name=controller" to see the Mbean details
Click on the "SayHello" button below to open and return to the results of the operation
JMX First Experience