Analyze the stack memory situation of java projects

1. Run the java project locally and use idea to develop it.
Enter jvisualvm
Insert image description here
2. A new window will be loaded, in which the memory situation will be analyzed.
Insert image description here
3. The java program running remotely
adds first parameters when starting the program.

// 在linux 运行脚本上添加  
-Djava.rmi.server.hostname=192.168.44.33 -Dcom.sun.management.jmxremote.port=8881 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -


192.168.44.33 is the address where the server is running and 8881 is the port.

At this time, add a remote input connection in jvisualvm to view the stack situation

In addition, startup parameter description:

// jvm的运行内存大小
java -Xms600m -Xmx1048m 
// 内存溢出会自动自动打印日志
-XX:+HeapDumpOnOutOfMemoryError -XX:NativeMemoryTracking=detail -XX:HeapDumpPath=/home/firefly/Outmemory.log 
//jvisualvm   连接
-Djava.rmi.server.hostname=192.168.44.33 -Dcom.sun.management.jmxremote.port=8880 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -
//远程debug 调试
Xdebug  -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 
//启动使用GMT时区时间
-Duser.timezone=GMT

3. Java programs running on Linux
use the command line to produce dump files

sudo jmap -histo:live pid >>/home/user/jmap.dump

Use MemoryAnalyzer to analyze this file and check for memory problems.
Insert image description here
4. In Linux systems, you can use some commands to check for memory problems.

// 分析各个进程所占内存运行状况
top

// 查看进程为pid 的各个线程运行情况
top -p pid -H

// 查看进程为pid 各个线程的详情
sudo jstack -l  pid  

// 查看进程为pid 各个存活的对象
sudo jmap -histo:live pid

//使用jmap查看堆栈信息
jmap -heap pid

//  3秒查看一次GC 执行 可以查看一下 老年代和年轻代的各种内存占用大小
jstat -gc 992  3000

Guess you like

Origin blog.csdn.net/rainAndyou/article/details/109687192