VisualVM can monitor threads and memory conditions, view the CPU time of methods and objects in memory, objects that have been GCed
, and reversely view the allocated stack (such as which objects are allocated to 100 String objects).
VisualVM is easy to use, has almost zero configuration, and is quite functional, including almost all the functions of other JDK built-in commands.
- memory information
- thread information
- Dump heap (local process)
- Dump thread (local process)
- Open heap dump. A heap dump can be
jmap
used to generate. - Open thread dump
- Generate application snapshots (including memory information, thread information, etc.)
- Performance analysis. CPU analysis (calling time of each method, check which methods take more time), memory analysis (
memory occupied by various objects, check which classes occupy more memory) - ...
start up
In the bin directory of the jdk installation directory, find jvisualvm.exe
and double-click to open it.
Under Linux, execute
$JAVA_HOME/bin/jvisualvm
to open
View thread information and thread dump
Monitor remote jvm processes
VisualJVM can monitor not only the local jvm process, but also the remote jvm process, which needs to be implemented with the help of JMX technology.
What is JMX?
JMX
(Java Management Extensions, Java Management Extensions) is a framework for implanting management functions for applications, devices, systems, etc. JMX can flexibly develop seamlessly integrated system, network and service management applications across a series of heterogeneous operating system platforms, system architectures and network transmission protocols.
Example: monitor remote tomcat jvm process
Modify the following configuration files of tomcat and restart tomcat
#在tomcat的bin目录下,修改catalina.sh,添加如下的参数
JAVA_OPTS="‐Dcom.sun.management.jmxremote
‐Dcom.sun.management.jmxremote.port=9999
‐Dcom.sun.management.jmxremote.authenticate=false
‐Dcom.sun.management.jmxremote.ssl=false"
#这几个参数的意思是:
#‐Dcom.sun.management.jmxremote :允许使用JMX远程管理
#‐Dcom.sun.management.jmxremote.port=9999 :JMX远程连接端口
#‐Dcom.sun.management.jmxremote.authenticate=false :不进行身份认证,任何用
户都可以连接
#‐Dcom.sun.management.jmxremote.ssl=false :不使用ssl
Use the visualvm tool to connect to the remote tomcat
- Step 1: Add a remote host
- Step 2: Add jmx connection
- Step 3: The usage is the same as the local jvm process