jstack来分析linux服务器上Java应用服务性能异常

使用jdk自带的jstack来分析linux服务器上应用服务性能异常:

1.top查找出哪个进程消耗的系统资源情况

[op1@jira ~]$ top

top - 19:23:43 up 22 days,  3:43,  1 user,  load average: 3.45, 2.52, 1.19

Tasks: 134 total,   1 running, 133 sleeping,   0 stopped,   0 zombie

Cpu(s): 57.3%us,  1.9%sy,  0.0%ni, 40.6%id,  0.0%wa,  0.1%hi,  0.1%si,  0.0%st

Mem:   6105924k total,  3466656k used,  2639268k free,    47512k buffers

Swap:  4194296k total,    42496k used,  4151800k free,  1328268k cached

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                    

15995 root      22   0 3437m 1.8g  40m S 355.6 30.9 221:04.19 java                                                                                                                                       

21165 op1       15   0 10876 1052  768 R  0.3  0.0   0:00.34 top                                                                                                                                          

    1 root      15   0 10364  580  548 S  0.0  0.0   0:01.07 init    

........                                                                                                                             

2.先输入top,然后再按shift+h 显示线程消耗资源

Tasks: 269 total,   1 running, 268 sleeping,   0 stopped,   0 zombie

Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:   6105924k total,  4425172k used,  1680752k free,   170816k buffers

Swap:  4194296k total,    42492k used,  4151804k free,  1729076k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                    

16215 root      18   0 3474m 2.2g  56m S 9999.0 37.8 112:00.66 java                                                                                                                                      

16208 root      15   0 3474m 2.2g  56m S 1962.2 37.8   0:59.05 java                                                                                                                                       

16114 root      16   0 3474m 2.2g  56m S 305.0 37.8   0:09.18 java                                                                                                                                        

16209 root      15   0 3474m 2.2g  56m S 291.1 37.8   0:08.76 java                                                                                                                                       

.....(这些线程都是进程15995下的)

 

3.jstack查找这个线程的信息

jstack [进程]|grep -A 10 [线程的16进制]

 

如:jstack 21125|grep -A 10 52f1(-A 10表示查找到所在行的后10行。21233用计算器转换为16进制52f1,注意转换后的十六进制字母是小写)

 

4.使用jstack来dump出所有线程的状态和调用堆栈并保存到本地文件dump_test

 

[root@jira bin]# ./jstack 15995 >> dump_test

posted @ 2013-11-29 14:50  mazj  阅读(1070)  评论(0编辑  收藏  举报