添加JVM参数,其中IP和端口号要根据实际情况配置,需要重启进程
-Dcom.sun.management.jmxremote.port=8903
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=xx.xx.xx.xx
GCLog配置
-Xloggc:$DIR/gcLog.txt
对象打印配置
-XX:+PrintClassHistogram
添加完成JVM参数后,可以用kill -3 pid命令会将对象打印输出到gcLog.txt文件中,如果执行java程序的时候,将输出重定向到文件中,则kill -3也会打印到重定向文件中。