JMX First Experience

Source: Internet
Author: User
Tags jconsole

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.