使用JMX监视应用程序服务器

时间:2015-12-14 15:45:47

标签: java jmx jmx-ws

我用JMX和Java

找到了这个简单的JBoss监控示例
public class JMXExample {

    public static void main(String[] args) throws Exception {
        //Get a connection to the JBoss AS MBean server on localhost
        String host = "localhost";
        int port = 9999;  // management-native port
        String urlString =
            System.getProperty("jmx.service.url","service:jmx:remoting-jmx://" + host + ":" + port);
        JMXServiceURL serviceURL = new JMXServiceURL(urlString);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
        MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

        //Invoke on the JBoss AS MBean server
        int count = connection.getMBeanCount();
        System.out.println(count);
        jmxConnector.close();
    }
}

我想每隔3秒调用一次这段代码来获取实时性能数据。

有没有办法打开一个到服务器的连接并发送频繁的请求?

1 个答案:

答案 0 :(得分:0)

如果将此代码部署为EJB,则可以将其设置为@Singleton @Startup,并使用@PostConstruct方法设置连接,同时根据{{1}定期收集度量标准}}。例如:

@Schedule