Monday, February 27, 2012

Finding top consumer Java Threads with Unix TOP command and JStack

1)ssunel@VTEKPSSUNEL:~$ top -c -b -H -n1 -d1 | head -n 20 | grep 'java\|CPU'

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                    
28763 ssunel    20   0 2893m 821m  10m R  100 10.3   0:38.97 /usr/java/bin/java
28518 ssunel    20   0 2893m 821m  10m S    2 10.3   0:00.30 /usr/java/bin/java
28667 ssunel    20   0 2893m 821m  10m S    2 10.3   0:00.07 /usr/java/bin/java

28733 ssunel    20   0 2893m 821m  10m S    2 10.3   0:00.11 /usr/java/bin/java 

2)Go to : here or use any other converter & convert decimal thread-id(s) [28763  -  28518  -  28667  -  28733 ] to hexedecimal.

Java thread identifiers will be something like that : 
pid    :  nid
28763  : 0x705b
28518 : 0x6f66
28667 : 0x6ffb
28733 : 0x703d

3)ssunel@VTEKPSSUNEL:~$ jstack <pid>

4) Search for the nativeId(s) in the thread dump : nid=0x705b or nid=0x6f66 or nid=0x6ffb or nid=0x703d

Example: 
"SocketListener" daemon prio=10 tid=0x0f474c00 nid=0x705b runnable [0x0386e000]
   java.lang.Thread.State: RUNNABLE
    at java.lang.Throwable.fillInStackTrace(Native Method)
    - locked <0x299364f4> (a java.nio.channels.NotYetBoundException)
    at java.lang.Throwable.<init>(Throwable.java:181)
    at java.lang.Exception.<init>(Exception.java:29)
    at java.lang.RuntimeException.<init>(RuntimeException.java:32)
    at java.lang.IllegalStateException.<init>(IllegalStateException.java:27)
    at java.nio.channels.NotYetBoundException.<init>(NotYetBoundException.java:30)
    at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:139)
    - locked <0x6567a198> (a java.lang.Object)
    at com.mycompany.smppgwsocket.smpp34server.Smpp34ServerSocketListener.run(Smpp34ServerSocketListener.java:08)

No comments:

Post a Comment