Introduction to JVisualVM and Its Use for Memory Leak Analysis and Remote Tomcat Monitoring
This article introduces JVisualVM, explains how to install and use its plugins for monitoring threads, CPU, memory and GC, demonstrates a Java memory‑leak simulation with code and JVM options, shows step‑by‑step analysis of heap dumps, and describes remote Tomcat monitoring via JMX.
VisualVM, a profiling sub‑project of NetBeans bundled with JDK 6 update 7, provides a graphical interface to monitor Java Virtual Machine (JVM) applications, displaying thread activity, memory usage, CPU time, garbage‑collection details, and allowing local or remote monitoring.
It can be launched via jvisualvm.exe and extended with various plugins that focus on GC, memory, threads, etc.; the most commonly used plugins are Monitoring, Threads, and Visual GC.
The article presents a case study for simulating a memory leak by defining a static HashMap and repeatedly creating TestMemory objects, with sample Java code and JVM parameters ( -Xms512m -Xmx512m -XX:-UseGCOverheadLimit -XX:MaxPermSize=50m ) to run the program and capture heap dumps.
import java.util.HashMap;
import java.util.Map;
public class CyclicDependencies {
private static final Map map = new HashMap();
public static void main(String args[]) {
try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); }
for (int i=0; i<1000000; i++) { TestMemory t = new TestMemory(); map.put("key"+i, t); }
System.out.println("first");
// additional loops and sleeps omitted for brevity
}
}Using VisualVM, the author compares Visual GC snapshots after different program phases (first, second, third, forth), observes continuous old‑generation GC without memory reduction, and identifies the leaking TestMemory instances via the sampler and instance view, confirming they are retained by the static HashMap .
The article also explains how to configure a remote Tomcat server for JMX monitoring by adding JVM options (e.g., -Djava.rmi.server.hostname , -Dcom.sun.management.jmxremote.port=18999 , disabling SSL and authentication), then adding the remote host and JMX connection in VisualVM to monitor the Tomcat process.
References to external blog posts are provided for further reading.
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.