启动jmx server 和jmx client,通过jconsole进入jmx server

然后通过其中远程进程,进入jmx client:

发现,两者可用的tab页不同, MBean的数量类型也不同:

如何理解呢?其实原因就是两者的MBeanServer不同, 前者是jmx自带的,后者是我new出来的。

访问JMImplementation 看看:

ObjectName jmxname = new ObjectName("JMImplementation:type=MBeanServerDelegate");
            javax.management.MBeanServerDelegateMBean jmxMBean = JMX.newMXBeanProxy(connection, jmxname ,
              javax.management.MBeanServerDelegateMBean.class);
   String notificationInfo = jmxMBean.getSpecificationName();
   System.out.println(notificationInfo);
//   for (int i = 0; i < notificationInfo.length; i++) {
//    System.out.println(notificationInfo.toString());
//   }

不过却不能访问jmx server的MBean。。

即使在jmx server端访问,也是失败

Hashtable<String, String> aa = new Hashtable<String, String>();
   aa.put("type", "MemoryPool");
   aa.put("name", "PS Eden Space");
   ObjectName memoryPoolMXBeanName  = new ObjectName("java.lang",aa );
   
         MemoryPoolMXBean memoryPoolMXBean = JMX.newMXBeanProxy(connection, memoryPoolMXBeanName ,
           MemoryPoolMXBean.class);
        
         MemoryType type = memoryPoolMXBean.getType();
         System.out.println(type);

二月 16, 2014 3:21:15 下午 sun.rmi.server.UnicastServerRef logCallException
FINE: RMI TCP Connection(2)-127.0.0.1: [127.0.0.1] exception:
javax.management.InstanceNotFoundException: java.lang:name=PS Eden Space,type=MemoryPool
 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095)
 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:643)
 at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:668)

。。。

原因: 此时的connection不是通往jmx server的connection、JMXConnectorServer,应该

通过MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();然后创建 JMXConnectorServer

或者可以通过ManagementFactory 访问:

List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
        for (Iterator iterator = memoryPoolMXBeans.iterator(); iterator
    .hasNext();) {
     MemoryPoolMXBean memoryPoolMXBean = (MemoryPoolMXBean) iterator.next();
     System.out.println(memoryPoolMXBean.getName());
  

  }

可见, 如果要访问jmx server内部的mbean(这些都可以理解为PlatformMBean 或者PlatformManagedObject),则需要使用ManagementFactory (静态类)

此外,这个类提供了静态方法访问jmx server的已注册的mbean 等方法,getPlatformManagementInterfaces等是前者抽象了的特殊方法:

Set<Class<? extends PlatformManagedObject>> set = ManagementFactory.getPlatformManagementInterfaces();
        for (Class<? extends PlatformManagedObject> class1 : set) {
   System.out.println(class1.getName());
  }

MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
  ObjectName name = new ObjectName("JMImplementation:type=MBeanServerDelegate");
  MBeanInfo beanInfo = platformMBeanServer.getMBeanInfo(name );
  MBeanAttributeInfo[] attributes = beanInfo.getAttributes();
  for (int i = 0; i < attributes.length; i++) {
   MBeanAttributeInfo beanAttributeInfo = attributes[i];
   System.out.println(beanAttributeInfo.getName());
  }

jmx server 和jmx client的更多相关文章

  1. 解决:安装SQL Server 2008 Native Client遇到错误(在Navicat premium新建sqlserver连接时 需要):An error occurred during ...HRESULT: 0x80070422(注意尾部的错误号)

    解决:安装SQL Server 2008 Native Client遇到错误(在Navicat premium新建sqlserver连接时 需要):An error occurred during . ...

  2. 在socket的server端处理client端发来的数据

    一.楔子 最近做了一个需求遇到一个坑,归结成一个小问题,其实就是在socket的server端处理client端发来的数据的问题,现将这个问题总结一下,本文将数据在server端以字典的形式存储. 另 ...

  3. 用同一台PC的两个网口实现Iperf的server端和client端

    用同一台PC的两个网口实现Iperf的server端和client端 2015年10月20日 20:35:11 阅读数:2943 有时候需要发包,仅仅需要一定速率的流量,并不需要关心收到报文的大小,一 ...

  4. 【翻译自mos文章】在RHEL7/OL7上安装Oracle 12.1.0.2的server端或者client时,报须要&quot;compat-libstdc++&quot;包

    在RHEL7/OL7上安装Oracle 12.1.0.2的server端或者client时,报须要"compat-libstdc++"包 来源于: Installation of ...

  5. 【Tech】CAS多机部署Server和Java Client端

    昨天尝试把cas的java client端部署到另外一台机器,结果就有问题了.(localhost部署cas server和java client端参见:http://www.cnblogs.com/ ...

  6. sql server 安装出现需要sqlncli.msi文件,错误为 microsoft sql server 2012 native client

    在安装sql server 2017 时出现 弹框标题为  microsoft sql server 2012 native client  内容为需要sqlncli.msi文件 去本地目录找本身的那 ...

  7. Server Tracking of Client Session State Changes Connection Management

    MySQL :: MySQL 8.0 Reference Manual :: 5.1.12 Connection Management https://dev.mysql.com/doc/refman ...

  8. nginx反向代理cas-server之2:生成证书,centOS下使用openssl生成CA证书(根证书、server证书、client证书)

    前些天搭好了cas系统,这几天一致再搞nginx和cas的反向代理,一直不成功,但是走http还是测试通过的,最终确定是ssl认证证书这一块的问题,原本我在cas服务端里的tomcat已经配置了证书, ...

  9. swoole深入学习 2. tcp Server和tcp Client

    这节来学习Swoole最基础的Server和Client.会通过创建一个tcp Server来讲解. server <?php class Server { private $serv; pub ...

随机推荐

  1. css3之景深

    perspective属性:(目前仅仅支持-webkit-perspective属性,视点距离) 值:number perspective-origin属性:(视点位置) 值:number% numb ...

  2. 高尔夫管理系统SSH

    登录-----------http://localhost:8080/GOLF/Denglu 一.Action 1.处理今日消费数据逻辑的 package com.chinasofti.golf.ac ...

  3. 使用C#代码部署SharePoint 2013开发包简单总结(一)

    这篇文章将总结下如何将自己开发的列表.Web部件.事件接收器等元素部署到SharePoint的服务器.因水平有限,我的做法未必是最佳实践,会有些错误理解和疏漏,欢迎各位高手批评指正——但一定要能给出更 ...

  4. AngularJS之ng-options的best practise

    废话不多说,直接上代码. function MySelectCtrl($scope) { $scope.Model = [ { id: 10002, MainCategory: '男', Produc ...

  5. Windows下nginx+php配置

    1. 首先,将 nginx.conf 中的 PHP 配置注释去掉. # pass the PHP scripts to FastCGI server listening on # #location ...

  6. 讲解版的导航高亮(新手福利)原生JS

    1.先写样式: 导航的排版样式: 导航对应高亮样式: .d6000f{ background:red; } .d6000f a{ color:#fff; } 我这个地方导航高亮样式为背景红色,字体颜色 ...

  7. STM32 GPIO外部中断总结

    一.STM32中断分组: STM32 的每一个GPIO都能配置成一个外部中断触发源,这点也是 STM32 的强大之处.STM32 通过根据引脚的序号不同将众多中断触发源分成不同的组,比如:PA0,PB ...

  8. php图片合成

    <?php//===================== 新建一个新的 GD 图像流并输出图像========================//header("Content-typ ...

  9. install mysql using binary and configure manu

    (1)下载,解压 (2)初始化数据库 ./scripts/mysql_install_db --defaults-file=../my.cnf --user=guofeng (3)启动命令 ./bin ...

  10. apache虚拟主机配置HTTPS

    win+apache+php的环境下做虚拟主机的https. 1.https用的是443端口,确定防火墙已经开放443了.2.http.conf要加载以下模块: #这两个是用来存放SSLSession ...