Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket information from Linux-Java thread dump

While analyzing a performance issue, I took continuous thread dumps for every 5 secs, and analyzed using samurai thread dump analyzer. Noticed that, many threads are in runnable state with below stack dump continuously on all the occurrences. But I couldn't find to which host they are communicating. I tried using the commands ss -t -a, watch ss -tp and netstat -A inet -p, but couldn't relate their results with the thread. Any idea? Thanks in advance.

Thread dump 2/5 "TP-Processor125"   prio=5 tid=0x25756 nid=0x649c RUNNABLE (JNI Native Code) - stats: cpu=828 blk=-1 wait=-1      java.lang.Thread.State: RUNNABLE      
     at java.net.SocketInputStream.socketRead0(Native Method)      
     at java.net.SocketInputStream.read(SocketInputStream.java:152)      
     at java.net.SocketInputStream.read(SocketInputStream.java:122)      
     at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)      
     at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)      
     at java.io.BufferedInputStream.read(BufferedInputStream.java:334)      
     at org.apache.jk.common.ChannelSocket.read(ChannelSocket.java:628)
     at org.apache.jk.common.ChannelSocket.receive(ChannelSocket.java:566)
     at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:693)
     at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
     at java.lang.Thread.run(Thread.java:745)      Locked synchronizers: count = 0
like image 382
Jaganathan Sadasivan Avatar asked Oct 20 '25 03:10

Jaganathan Sadasivan


1 Answers

The nid is actually the process/thread ID of the underlying OS (at least for Linux), albeit in hex notation. Convert to decimal pid and use

lsof -p pid |grep -Ei 'tcp|socket'

to learn more about the socket connections used. It may turn out though, that all sockets are opened by the main thread, in which case the sub-threads only inherit several (many) so it may be difficult to see which thread it connected where.

If lsof does not show the thread of the main process (seems it indeed does not) you may have to resolve to looking into /proc/<pid>/fd.

like image 127
Harald Avatar answered Oct 21 '25 18:10

Harald