JMX示例

HelloJMXMBean.java

package jmx;

/**
 * Created by george on 14-8-21.
 */
public interface HelloJMXMBean {
    public String getName();
    public void setName(String name);
    public void printHello();
    public void printHello(String whoName);
}

HelloJMX.java

package jmx;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

/**
 * Created by george on 14-8-21.
 */
public class HelloJMX implements HelloJMXMBean {
    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void printHello() {
        System.out.println("HelloJMX, " + name);
    }
    public void printHello(String whoName) {
        System.out.println("HelloJMX, it is " + whoName);
    }

    public static void main(String[] args) throws Exception {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();

        ObjectName helloName = new ObjectName("george:name=HelloJMX");
        server.registerMBean(new HelloJMX(), helloName);


        Thread.sleep(Long.MAX_VALUE);
    }

}

 

1. run....

2. jconsole....

 

posted @ 2014-08-26 16:08  番茄瓜园  阅读(140)  评论(0编辑  收藏  举报