jstack的使用

到jdk的安装目录的bin目录下

执行jstack -l 2574 > /opt/proda/j.txt(将对应的文件dump到服务器的某个目录中)

排查CPU使用率过高,某个进程中哪个线程使用率高。

网址:http://www.cnblogs.com/skyaccross/archive/2012/12/22/2829000.html 分析java程序中cpu占用过高的线程 skyaccross。

比如排查消息网关CPU使用率高。

1)先确定消息网关的进程PID。该PID为11436.

 

 

 

2)通过top -H -p PID确定进程PID中哪些线程使用CPU高。如下,11801和10245使用CPU相对就高。

 

 

 

3)dump当前的进程的堆栈。

[root@hs7 bin]# sudo -u node ./jstack 11436 > /tmp/dump11436

 

 

 

4)将线程的pid 转成16进制,比如11801 = 0x2E19

   到第一步dump出来的 11436.stack 里面找0x2E19 就知道是哪个线程了

 

 

 

 

 

 

从而知道是http-bio-8581-Acceptor-0和RMI TCP Connection(259)-172.16.101.69线程占用较高的CPU。

 

 

 

 

 

 

 

 

http-bio-8581-exec-281

 

"http-bio-8581-exec-902" #952 daemon prio=5 os_prio=0 tid=0x00007f5688ba4000 nid=0x1e75 waiting on condition [0x00007f5436526000]

   java.lang.Thread.State: WAITING (parking)

         at sun.misc.Unsafe.park(Native Method)

         - parking to wait for  <0x0000000082714110> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)

         at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)

         at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)

         at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)

         at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104)

         at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32)

         at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)

         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)

         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

         at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

         at java.lang.Thread.run(Thread.java:748)

 

 

"http-bio-8581-exec-148" #198 daemon prio=5 os_prio=0 tid=0x00007f56885aa000 nid=0x1b80 waiting on condition [0x00007f5469ad9000]

   java.lang.Thread.State: WAITING (parking)

         at sun.misc.Unsafe.park(Native Method)

         - parking to wait for  <0x0000000082714110> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)

         at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)

         at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)

         at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)

         at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104)

         at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32)

         at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)

         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)

         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

         at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

         at java.lang.Thread.run(Thread.java:748)

 

 

 

 

"RMI TCP Connection(216)-172.16.101.69" #2077 daemon prio=5 os_prio=0 tid=0x00007f98cc006800 nid=0x78c1 runnable [0x00007f9922bfb000]

   java.lang.Thread.State: RUNNABLE

         at java.net.SocketInputStream.socketRead0(Native Method)

         at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)

         at java.net.SocketInputStream.read(SocketInputStream.java:171)

         at java.net.SocketInputStream.read(SocketInputStream.java:141)

         at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)

         at java.io.BufferedInputStream.read(BufferedInputStream.java:265)

         - locked <0x0000000082c7d508> (a java.io.BufferedInputStream)

         at java.io.FilterInputStream.read(FilterInputStream.java:83)

         at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$5/436481274.run(Unknown Source)

         at java.security.AccessController.doPrivileged(Native Method)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)

         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

         at java.lang.Thread.run(Thread.java:748)

 

 

"RMI TCP Connection(218)-172.16.101.203" #2081 daemon prio=5 os_prio=0 tid=0x00007f98cc007800 nid=0x78c5 runnable [0x00007f96cebb0000]

   java.lang.Thread.State: RUNNABLE

         at java.net.SocketInputStream.socketRead0(Native Method)

         at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)

         at java.net.SocketInputStream.read(SocketInputStream.java:171)

         at java.net.SocketInputStream.read(SocketInputStream.java:141)

         at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)

         at java.io.BufferedInputStream.read(BufferedInputStream.java:265)

         - locked <0x0000000082c1c5a8> (a java.io.BufferedInputStream)

         at java.io.FilterInputStream.read(FilterInputStream.java:83)

         at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$5/436481274.run(Unknown Source)

         at java.security.AccessController.doPrivileged(Native Method)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)

         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

         at java.lang.Thread.run(Thread.java:748)

 

 

"RMI TCP Connection(217)-172.16.101.203" #2075 daemon prio=5 os_prio=0 tid=0x00007f98cc005800 nid=0x78bf runnable [0x00007f96cedb2000]

   java.lang.Thread.State: RUNNABLE

         at java.net.SocketInputStream.socketRead0(Native Method)

         at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)

         at java.net.SocketInputStream.read(SocketInputStream.java:171)

         at java.net.SocketInputStream.read(SocketInputStream.java:141)

         at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)

         at java.io.BufferedInputStream.read(BufferedInputStream.java:265)

         - locked <0x0000000082c84038> (a java.io.BufferedInputStream)

         at java.io.FilterInputStream.read(FilterInputStream.java:83)

         at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$5/436481274.run(Unknown Source)

         at java.security.AccessController.doPrivileged(Native Method)

         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)

         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

         at java.lang.Thread.run(Thread.java:748)

 

 

"VM Thread" os_prio=0 tid=0x00007f996808a800 nid=0x7095 runnable

posted on 2022-03-24 09:59  seamy  阅读(526)  评论(0编辑  收藏  举报