博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MX4j与JDK1.6不兼容的地方
阅读量:4118 次
发布时间:2019-05-25

本文共 1815 字,大约阅读时间需要 6 分钟。

最近想做一个通用,可扩展的数据采集框架,想把这个框架构建在JMX上,想选用MX4j,结果居然在jdk1.6下运行examples会提示类找不到,明明这个类是存在,比如下面的例子会提示mx4j.tools.naming.NamingService这个类找不到,郁闷!搞了一下午,后来好不容易才找到原来mx4j跟jdk1.6有一些不兼容,解决办法是运行虚拟机时候加入参数,意思是用自定义的MBServer替换默认的

“-Djavax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder"。

package mx4j.examples.remote.simple;

import javax.management.MBeanServer;

import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;

/**

 * This example shows the simplest way to setup a JSR 160 connector server.
 * It uses the standard JSR 160 RMIConnectorServer, and if you're familiar with
 * RMI, you'll know that a JNDI server like the rmiregistry is needed
 * in order to register the server stub that will be looked up by the client.
 *
 * @version $Revision: 1.3 $
 */
public class Server
{
   public static void main(String[] args) throws Exception
   {
      // The MBeanServer
      MBeanServer server = MBeanServerFactory.createMBeanServer();

      // Register and start the rmiregistry MBean, needed by JSR 160 RMIConnectorServer

      ObjectName namingName = ObjectName.getInstance("naming:type=rmiregistry");
      server.createMBean("mx4j.tools.naming.NamingService", namingName, null);
      server.invoke(namingName, "start", null, null);
      int namingPort = ((Integer)server.getAttribute(namingName, "Port")).intValue();

      String jndiPath = "/jmxconnector";

      JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:" + namingPort + jndiPath);

      // Create and start the RMIConnectorServer

      JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
      connectorServer.start();

      System.out.println("Server up and running");

   }
}

转载地址:http://ogdpi.baihongyu.com/

你可能感兴趣的文章
Linux基础系列-定时器与时间管理
查看>>
Linux基础系列-可执行程序的产生过程
查看>>
Linux基础系列-Kernel 初始化宏
查看>>
Linux子系统系列-I2C
查看>>
<iOS>关于自定义description的一点用法
查看>>
Unix 命令,常用到的
查看>>
DLL中建立进程共享数据段需要注意的语法问题
查看>>
服务器端技术----Http请求的处理过程
查看>>
C语言-预处理指令2-条件编译
查看>>
C语言-预处理指令3-文件包含
查看>>
C语言-变量类型
查看>>
C语言-static和extern关键字1-对函数的作用
查看>>
C 语言-static和extern关键字2-对变量的作用
查看>>
【JavaScript 教程】浏览器—History 对象
查看>>
还不会正则表达式?看这篇!
查看>>
100道+ JavaScript 面试题,助你查漏补缺
查看>>
JavaScript深入理解之闭包
查看>>
这才是学习Vite2的正确姿势!
查看>>
7 个适用于所有前端开发人员的很棒API,你需要了解一下
查看>>
25个构建Web项目的HTML建议,你需要了解一下!
查看>>