Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (3.5k points)

How to activate JMX on a JVM for access with jconsole?

1 Answer

0 votes
by (46k points)

The relevant documentation can be found here:

http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html

Start your program with following code:

-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

For example like this:

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 is not necessarily neededbut without it, it doesn't work on Ubuntu. The error would be something like this:

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)

see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6754672

Also be careful with -Dcom.sun.management.jmxremote.authenticate=false which makes access available for anyone, but if you only use it to track the JVM on your local machine it doesn't matter.

In some cases I was not able to reach the server. This was then fixed if I set this parameter as well: -Djava.rmi.server.hostname=127.0.0.1

Related questions

Browse Categories

...