如何在JVM上激活JMX以使用jconsole进行访问?
相关文档可在此处找到:
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上运行。该错误将是这样的:
-Dcom.sun.management.jmxremote.local.only=false
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.authenticate=false使任何人都可以访问,但是如果仅使用它来跟踪本地计算机上的JVM,则没关系。
Dcom.sun.management.jmxremote.authenticate=false
更新:
在某些情况下,我无法访问服务器。如果我也设置了此参数,则此问题已解决:-Djava.rmi.server.hostname=127.0.0.1
Djava.rmi.server.hostname=127.0.0.1