Visual VM can monitor the running status of jvm in real time
Press Perform GC will immediately perform a GC
press Heap Dump will generate a memory information report
You can also monitor SQL
Use visualVM to troubleshoot memory leaks
Simulate memory overflow:
import java.util.ArrayList;
public class OOM {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
int i = 0;
while (true) {
list.add(i++);
}
}
}
Open the hprof file using visual VM and
found that Integer occupies 97.9% of the memory.
Jmap view memory information or memory details under dump
You can use visual VM to view this file, generally this approach is used when Linux has no graphical interface.
Other troubleshooting tools:
jconsole java monitoring and management console
jconsole actually contains all the following instructions, but if you need to use the following instructions on a Linux system without an interface
jps view the currently running java program
jstat -gcutil pid interval time (milliseconds)
Unit: Percentage of memory
s0: survivor0 area, s1: survivor1 area, E: eden area, O: old area, M: meta space, CSS: compression type
YGC: youngGC times, YGCT: youngGC time, FGC: FullGC times, FGCT: FullGC time
GCT: GC time average time