When developing large Java projects, we inevitably encounter memory leaks and performance bottlenecks, such as unreleased connections to files, networks, and databases, and unoptimized algorithms. If not addressed, this can be a very serious concern as development progresses. Today I will introduce you to the use of VisualVM. (The specific analysis of test data will not be elaborated here, only the use of the tool and basic analysis will be introduced.) I will introduce the use of the tool from the following aspects:

  • The preparatory work
  • The plug-in USES
  • Based on analysis of

First, preparation

1. Linux environment where the service resides

/ root @ localhost ~ # CD/usr/Java/jdk1.8.0 _162 / bin /

[root@localhost bin]# vim jstatd.all.policy

Add the following code:

Grant the codebase “file: / usr/Java/jdk1.8.0 _162 / lib/tools. The jar” {permission Java. Security. AllPermission; };

Pay attention to

/usr/java/jdk1.8.0_162/bin/ and /usr/java/jdk1.8.0_162/lib/tools.jar are my Java paths. Replace it with your own path

2. Start jstard

[root @ localhost bin] #. / jstatd – J – Djava. Security policy = jstatd. All. The policy – J – Djava. Rmi server hostname = 192.168.134.128 – p 3333 -J-Djava.rmi.server.logCalls=true

Pay attention to

Hostname =192.168.134.128 Please replace with your own service IP address. -P 3333 Can be replaced with your own port

3. Download the VisualVM

Visualvm.github. IO /

4. Run the VisualVM

4.1 Adding a Remote Service

Special attention:

  1. If you cannot connect to the server, check that the JSTard is started
  2. If the server cannot be connected, check whether the firewall blocks the port

Two, plug-in use

1. Set the plug-in resource link

I currently use VisualVM is 1.4.1 version, so use plugin resources link is here: VisualVM. Making. IO/uc/release1… According to their own use version to add: visualvm. Making. IO/pluginscent…

Example 2.

  • Visual GC is the plug-in I added

3. Basic analysis

Heap, Metaspace, Classes, Threads, Metaspace, Metaspace, Metaspace, Classes, Threads, etc