jstack(查看线程)、jmap(查看内存)和jstat(性能分析)
1.使用top,查询出最耗内存的cpu对应的pid
/opt/java8/bin/jstack
Usage:
jstack [-l] <pid> 举例:jstack -l 8748
(to connect to running process) 连接活动线程
jstack -F [-m] [-l] <pid>
(to connect to a hung process) 连接阻塞线程
jstack [-m] [-l] <executable> <core>
(to connect to a core file) 连接dump的文件
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server) 连接远程服务器
Options:
-F to force a thread dump. Use when jstack <pid> does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message
2.查询pid下有多少个线程:jstack -l pid | grep 'java.lang.Thread.State' | wc -l 显示 'java.lang.Thread.State'的行数
举例:jstack -l 8748 | grep 'java.lang.Thread.State' | wc -l --->返回线程数 266
3.把jstack记录保存到文件里 :
cd /log/java/push-service
jstack -l pid >> 123.txt , rz 上传命令,sz 123.txt 下载命令
jstack 12652 | head -100
4.查看当前进程消耗资源的线程pid top -Hp pid
5 将线程Pid转为16进制,根据该16进制值去打印的堆栈日志内查询,查看该线程所驻留的方法位置。
printf "%x\n" 17880
45d8