码迷,mamicode.com
首页 > 其他好文 > 详细

JMX示例

时间:2014-08-26 17:02:06      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   io   for   ar   div   log   

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....

 

JMX示例

标签:style   blog   color   java   io   for   ar   div   log   

原文地址:http://www.cnblogs.com/niulang85/p/3937471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!