如何在JVM上激活JMX以使用jconsole进行访问?
当前回答
步骤1:使用以下参数运行应用程序。
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
上述参数将应用程序绑定到端口9999。
步骤2:在命令提示符或终端中执行命令jconsole来启动jconsole。
选择“远程进程:”并输入url为{IP_Address}:9999,然后单击连接按钮连接到远程应用程序。
您可以参考此链接以获得完整的应用程序。
其他回答
连同下面的命令行参数,
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
在linux服务器上,有时imx连接不成功。这是因为,在云Linux主机中,在/etc/hosts中使主机名解析为主机地址。
修复它的最好方法是,从网络中的其他机器ping特定的linux服务器,并使用该主机IP地址
-Djava.rmi.server.hostname=IP address that obtained when you ping that linux server.
但是永远不要依赖于你从linux服务器上使用ifconfig.me获得的ipaddress。你得到的IP是掩码的,在主机文件中。
相关文件可在此找到:
http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
用以下参数启动程序:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
比如这样:
java -Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9010 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar Notepad.jar
-Dcom.sun.management.jmxremote.local。Only =false不一定是必需的 但是如果没有它,它就不能在Ubuntu上工作。误差是这样的 这样的:
01 Oct 2008 2:16:22 PM sun.rmi.transport. customer .TCPTransport$AcceptLoop executeAcceptLoop
WARNING: RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=37278] throws
java.io.IOException: The server sockets created using the LocalRMIServerSocketFactory only accept connections from clients running on the host where the RMI remote objects have been exported.
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:89)
at sun.rmi.transport. customer .TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:387)
at sun.rmi.transport. customer .TCPTransport$AcceptLoop.run(TCPTransport.java:359)
at java.lang.Thread.run(Thread.java:636)
参见http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6754672
还要小心使用-Dcom.sun.management.jmxremote。验证= false, 任何人都可以访问,但是如果您只使用它来跟踪JVM 您的本地机器并不重要。
更新:
在某些情况下,我无法连接到服务器。如果我也设置了这个参数,这个问题就得到了解决:-Djava.rmi.server.hostname=127.0.0.1
在Linux上,我使用以下参数:
-Djavax.management.builder.initial=
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
我还编辑了/etc/hosts,以便主机名解析为主机地址(192.168.0.x),而不是环回地址(127.0.0.1)
步骤1:使用以下参数运行应用程序。
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
上述参数将应用程序绑定到端口9999。
步骤2:在命令提示符或终端中执行命令jconsole来启动jconsole。
选择“远程进程:”并输入url为{IP_Address}:9999,然后单击连接按钮连接到远程应用程序。
您可以参考此链接以获得完整的应用程序。
注意,Java 6的最新版本允许jconsole将自己附加到正在运行的进程上,即使在没有JMX咒语的情况下启动了进程。
如果可以使用jvisualvm,也可以考虑jvisualvm,因为它提供了大量关于运行进程的信息,包括一个分析器。
推荐文章
- 如何排序一个数组列表在Java
- 是否有(Java)包组织的最佳实践?
- 如何从Eclipse中的开放资源对话框中隐藏.class文件?
- 将日期字符串解析为java.util.Date时,不合法的模式字符'T'
- 使用Mockito的泛型“any()”方法
- 如何使用Java属性文件?
- 我如何修复一个NoSuchMethodError?
- Maven surefire找不到ForkedBooter类
- Java 8:我如何在流中使用异常抛出方法?
- 去下一次迭代在java For循环
- 在Java中使用什么数据类型来表示钱?
- Class.getResource()和ClassLoader.getResource()之间的区别是什么?
- 如何通过传递特定日期来确定星期几?
- 如何将DecimalFormat的小数分隔符从逗号更改为点/点?
- 控制jar工件的Maven最终名称