java-如何使JMX简单

点点圈 提交于 2019-12-14 06:10:43

我需要在30种不同的类中向JMX公开大约60种操作.用DynamicMBean制作它有点烦人.我正在寻找一种快速而优雅的方法.

 

我知道Spring具有注释的好方法,但是我在这个项目中没有使用spring.

最佳答案

请看一下我的SimpleJmx Java package,它旨在通过使用注释的JMX轻松发布bean.它还具有客户端代码.

 

快速代码示例:

 

// you can also use the platform mbean server
JmxServer jmxServer = new JmxServer(8000);
jmxServer.start();
// register our lookupCache object defined below
jmxServer.register(lookupCache);
...
jmxServer.stop();

这是定义bean的方法.

 

@JmxResource(domainName = "j256", description = "Lookup cache")
public class LookupCache {
    @JmxAttributeField(description = "Number of hits in the cache")
    private int hitCount;
    ...

    @JmxOperation(description = "Flush the cache")
    public void flushCache() {
       ...
    }
}

欢迎反馈.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!