使用JMX的多个Java应用程序 [英] Multiple Java Applications using JMX

查看:199
本文介绍了使用JMX的多个Java应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JMX的新手,我尝试实现的目标如下:我想使用JMX来监视同一Java-Application的多个实例。问题是,此应用程序可能同时运行多次。我需要监视来自另一个(远程)主机的JMX值。

I'm very new to JMX, and what I try to achieve is the following: I want to use JMX for monitoring multiple instances of the same Java-Application. The problem is, that this application might be run multiple times at the same time. I need the possibility to monitor the JMX values from another (remote) host.

示例Java-Application:

Example Java-Application:

public class Test {
  public static void main(String[] args) {
    while(true) {
      try {
        Thread.sleep(1000);
        System.out.println("I'm running");
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
}

已编译使用 javac Test.java 然后使用

java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false \
-Djava.net.preferIPv4Stack=true \
Test

应用程序现在运行,但我不知道如何从 jconsole 连接到此进程:我可以使用 netstat 找出JVM侦听的端口,但我无法连接,因为我在连接时收到表中没有这样的对象异常。

The application now runs, but I do not know how to connect to this process from jconsole: I can use netstat to find out the port on which the JVM listens but I cannot connect because I receive a "no such object in table" exception when connecting.

如果我运行它使用

java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false \
-Djava.net.preferIPv4Stack=true \
-Dcom.sun.management.jmxremote.port=1412 \
Test

,我可以使用 jconsole 1.2.3.4:1412 >。 但是:我无法在不修改端口的情况下第二次运行此应用程序,这非常符合逻辑,因为应用程序无法再次绑定到端口。

, I can connect to 1.2.3.4:1412 using jconsole. But: I cannot run this application a second time without modifiying the port, which is quite logical as the application cannot bind to the port a second time.

如何多次运行相同的应用程序(使用相同的命令行!)然后连接到多个实例?

推荐答案


我可以使用jconsole连接到1.2.3.4:1412。但是:我无法在不修改端口的情况下第二次运行此应用程序,这非常符合逻辑,因为应用程序无法再次绑定到端口。

I can connect to 1.2.3.4:1412 using jconsole. But: I cannot run this application a second time without modifiying the port, which is quite logical as the application cannot bind to the port a second time.

你的每个JVM都必须在不同的端口上运行。

Right each of your JVMs is going to have to live on a different port.


如何运行相同的应用程序多个时间(使用相同的命令行!)然后连接到多个实例?

How can I run the same application multiple times (with the same commandline!) and then connect to the multiple instances?

通过在不同的端口上运行它们:

By running them on a different port:

java -Dcom... -Dcom.sun.management.jmxremote.port=1412 Test
java -Dcom... -Dcom.sun.management.jmxremote.port=1413 Test

你也可以使用 port = 0 获取动态RMI端口,但我不确定你将如何远程查看。

You can also use the port=0 to get a "dynamic" RMI port but I'm not sure how you are going to see that remotely.

您可以考虑使用我的 SimpleJMX 软件包,这使得整个JMX bean的发布超级优秀ASY。它还允许您轻松地以编程方式将JMX发布到不同的端口。

You might consider using my SimpleJMX package which makes the whole publishing of JMX beans super easy. It also allows you to publish JMX to different ports easily and programably.

这篇关于使用JMX的多个Java应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆