有两种方式,一种使用RMI框架(即Remote Method Invoke 远程方法调用),RMI框架详解:http://haolloyin.blog.51cto.com/1177454/332426/。一种使用JMX(Java Management Extensions,即Java管理扩展), JMX是一个为应用程序、设备、系统等植入管理功能的框架。它们两个在VisualVM中提供的功能都不完善,RMI缺少CPU监控而JMX缺少VisualGC。
第一种方式: 通过jstated启动RMI服务见http://www.blogjava.net/titanaly/archive/2012/03/20/372318.html
第二种方式:配置JMX远程监控jvm
1. Run LongSleep.java with the JMX agent turned on without requiring any connection authentication or SSL certificate:
C:\herong>\progra~1\java\jdk1.8.0\bin\java -Dcom.sun.management.jmxremote.port=6789 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false LongSleep
2. Run Java VisualVM and click "File > Add JMX Connection..." menu. You will see a dialog box displayed.
3. Enter "localhost:6789" in the "Connection" field and click OK. You will see that VisualVM connects to the LongSleep.java JVM through the JMX agent.
Once connected, you can monitor the remote JVM in the same way as a local JVM.
The picture below shows File menu entries for connecting Java VisualVM to JVM processes running on a remote machine: