The jmx of Java

Source: Internet
Author: User
Tags jconsole

the jmx of JavaThe definition and architecture of JMX is unknown, see Baidu Encyclopedia:


Http://baike.baidu.com/link?url=6QzGGEqphTmpft3ll5mXmDNVRdvLRZhkvGaqAWyO6EliwrHeIwt5bdMd188iMlzylxoxr7gRbtIWn2NQODBLZa


code example:It 's no different than creating a normal bean:
Package com.doctor.java.jmx;/** * @author sdcuike * * @time February 9, 2016 PM 9:47:04 *  * @see http://www.journaldev.com/135 2/what-is-jmx-mbean-jconsole-tutorial * The      interface name must end with Mbean */public interface Systemconfigmbean { Public    void Setthreadcount (int noofthreads);    public int getthreadcount ();    public void Setschemaname (String schemaName);    Public String getschemaname ();    Any method starting with get and set is considered    //as attributes getter and setter methods, so I am    //Usin G do* for operation.    Public String doconfig ();}



Package com.doctor.java.jmx;/** * @author sdcuike * * @time February 9, 2016 PM 9:51:53 */public class Systemconfig implements Sys Temconfigmbean {    private int threadcount;    Private String schemaName;    Public systemconfig (int threadcount, String schemaName) {        this.threadcount = threadcount;        This.schemaname = SchemaName;    }    @Override public    void Setthreadcount (int noofthreads) {        this.threadcount = noofthreads;    }    @Override public    int Getthreadcount () {        return threadcount;    }    @Override public    void Setschemaname (String schemaName) {        this.schemaname = schemaName;    }    @Override public    String getschemaname () {        return schemaName;    }    @Override public    String doconfig () {        return ' No of threads= ' + This.threadcount + "and DB Schema name=" + this. SchemaName;}    }

Then we create a test example:
Package Com.doctor.java.jmx;import Java.lang.management.managementfactory;import Java.util.concurrent.TimeUnit; Import Javax.management.instancealreadyexistsexception;import Javax.management.mbeanregistrationexception;import Javax.management.mbeanserver;import Javax.management.malformedobjectnameexception;import Javax.management.notcompliantmbeanexception;import javax.management.objectname;/** * @author sdcuike * * @time    February 9, 2016 PM 9:56:27 */public class Systemconfigmanagement {private static final int default_no_threads = 10;    private static final String Default_schema = "DEFAULT"; public static void Main (string[] args) throws Malformedobjectnameexception, Instancealreadyexistsexception, Mbeanregistrationexception, Notcompliantmbeanexception, interruptedexception {//Get the Mbean server Mbean        Server mbeanserver = Managementfactory.getplatformmbeanserver (); Register the MBean systemconfig systemconfig = new Systemconfig (default_no_threads, DefauLt_schema);        ObjectName ObjectName = new ObjectName ("Com.doctor.java.jmx:type=systemconfig");        Mbeanserver.registermbean (Systemconfig, objectName);            Do {TimeUnit.SECONDS.sleep (3); System.out.println ("Thread count=" + systemconfig.getthreadcount () + "::: Schema name=" + systemconfig.getschemaname ())        ;    } while (Systemconfig.getthreadcount ()! = 0); }}

Run:when running, we must enable the virtual machine option -dcom.sun.management.jmxremote


Run
Now let's modify the variables with the Java tool Jconsole:

To Modify a variable value:





To perform the modification:

look at the output of the program we run:
whether the modified property is in effect.


The jmx of Java

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.