java print thread, heap dump
View pid
The ips command finds the pid of your current system name. The pid is very important. Many subsequent commands are queried based on the pid.
Note: the tomcat is bootstrap
View thread snapshot
Example of jstack -l pid :
jstack -l 12340 >a.text
Get thread snapshot information and redirect to the current directory a.text
Note: We will talk about thread snapshot analysis later
Heap snapshot
jmap -dump:format=b,file=dump.txt pid
jmap -dump:format=b,file=dump.txt 12340
Snapshots need to use tools
jvisualvm
Jdk comes with a graphical interface, which can automatically generate thread dumps, heap dumps, and visualize memory allocation tools
jconsole
Similar to jvisualvm, both are graphical interfaces
Automatically print heap dump when memory overflows
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=D:\temp
-Xms20M
-Xmx20M
When the memory overflows, head dump the file, and then analyze the heap memory usage according to the tool.
jmap -head pid
Print heap memory usage
Print gc log
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-Xloggc:D:/temp/gclogs
MinorGC
2020-09-06T15:45:38.653+0800: 0.330: [GC (Allocation Failure) [PSYoungGen: 5632K->504K(6144K)] 5632K->1496K(19968K), 0.0019669 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Analysis :
2020-09-06T15:45:38 : time
38.653+0800: 0.330 : jvm start gc time
GC (Allocation Failure) : the identification of MinorGC and FullGC, this time represents MinorGC
PSYoungGen : refers to Parallel Scavenge) is Eden +FromSpace
5632K->504K(6144K) : the usage of the young generation (size of the young generation)
5632K->1496K(19968K) : the usage of the entire heap before and after collection, the total heap size is
0.0019669 secs : the ParNew collector marks and copies the young generation alive The time spent by the object
FullGC
2020-09-06T15:45:39.978+0800: 1.656: [Full GC (Metadata GC Threshold) [PSYoungGen: 441K->0K(5120K)] [ParOldGen: 10846K->6883K(13824K)] 11287K->6883K(18944K), [Metaspace: 20298K->20298K(1067008K)], 0.0258899 secs] [Times: user=0.16 sys=0.00, real=0.03 secs]
demo
mat analyzes memory, thread status, etc.
Main interface information
Histogram
You can see which type of memory in which objects occupy more. At this time, we make sure that the object of this class of student occupies most of the memory. We continue to analyze
Right click: Merge shortest Path to GC Roots–>exclude all phantom/weak/soft etc.reference to view the call chain and find the thread @ 0xff3fe388
Leak Suspects
Mat will help us analyze the problem, we can find which thread, check the stack data to find the problem