About JMX

原创 2006年05月25日 16:43:00

Some benefits of using JMX in your applications
■ Configuration—Using MBeans to make your applications more configurable.
■ Componentization—Using MBeans to break your applications into components,allowing you to alter or replace component implementations.
■ MBeans using MBeans—Combining both previous concepts, one MBean used another MBean to initialize one of its member variables.

**Using MBean notifications**

  Emitting notifications is a powerful tool and can be used for communication,alerts, and more. Because notifications can contain important information and valuable data, it is a good idea to keep a record of them.

  An MBean wanting to emit Notification objects needs to extend the NotificationBroadcasterSupport class.If the MBean implements the NotificationBroadcaster interface in order to send notifications, then it also defines a method addNotificationListener().Because you have manually created this MBean, you can also invoke its add listener method to add your own listener.

  About notification,you can print it or persist it.

  To persist notifications,you can either create an MBean to act as a listener on every NotificationBroadcaster in the agent, or you can have each MBean manage its own notification persistence.

  About the latter option,you need to use the sendNotification() method, inherited from the NotificationBroadcasterSupport super class.

Example:

import javax.management.*;

public class Polling extends NotificationBroadcasterSupport implements PollingMBean, Runnable{
  private boolean stop = true;
  private long interval = 1000;
  private String info="Notify!";

  public Polling(){
  }

  public void setInterval( long interval ){
    long temp = this.interval;
    this.interval = interval;
    AttributeChangeNotification notif = new AttributeChangeNotification( this, 0, System.currentTimeMillis(), "Attribute Change", "interval", "long", new Long( temp ), new Long( interval ) );
    sendNotification( notif );
  }

  public void start(){
    try
    {
      stop = false;
      Thread t = new Thread( this );
      t.start();
    }
    catch( Exception e ){
      e.printStackTrace();
    }
  }

  public void stop(){
    stop = true;
  }

  public void run(){
    while( !stop ){
      try{
        Thread.sleep( interval );
        System.out.println( "Polling" );
      }
      catch( Exception e ){
        e.printStackTrace();
      }
      Notification notif = new Notification("com.neu.notify.Polling",this,-1,System.currentTimeMillis(),info);
      sendNotification( notif );
    }
  }
  
  public void sendNotification(Notification notify){
   //Save info
   super.sendNotification(notify);
  }

}

 

相关文章推荐

jmx-jvm配置

  • 2014年11月17日 09:58
  • 1KB
  • 下载

zabbix监控多实例tomcat--不使用JMX

用zabbix监控tomcat,网上搜索大部分都是通过配置JMX端口来进行监控。这个方法对只有一个tomcat的情况支持的还是不错的。 此文章针对同一主机多tomcat实例的情况...

toomcat jmx

  • 2013年01月16日 15:31
  • 8KB
  • 下载

JMX小例子以及介绍

  • 2011年06月29日 15:32
  • 940KB
  • 下载

JMX-Console控制台安全配置

默认情况下任何用户直接通过http://hostname:8080/jmx-console的URL地址就可以浏览JBOSS的部署管理信息,不需要任何用户名和密码就可以进入此页面,很方便,但真正使用起来...

java of core jmx

  • 2010年11月07日 20:55
  • 26KB
  • 下载

jmx通过客户端访问的问题

I'm trying to implement JMX server side and client side. I have the following xml in the server...

JMX实战

  • 2007年04月20日 12:59
  • 4.76MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:About JMX
举报原因:
原因补充:

(最多只允许输入30个字)