Threads in ‘runnable’ state consume CPU. So when you are analyzing thread dumps for high CPU consumption, threads in ‘runnable’ state should be thoroughly reviewed. Typically, in thread dumps several threads are classified in ‘RUNNABLE’ state. But in reality several of them wouldn’t be actually running, rather they would be just waiting. But still, JVM classifies them in ‘RUNNABLE’ state. You need to learn to differentiate from really running threads with pretending/misleading RUNNABLE threads.
Example
Below is the real world thread dump excerpt. In these stack traces, threads aren’t actually in ‘RUNNABLE’ state, i.e. they are not actively executing any code. They are just waiting on the sockets to read or write. It’s because JVM doesn’t really know what thread is doing in a native method, JVM classifies them in ‘RUNNABLE’ state. Real running threads would consume CPU, whereas these threads are on I/O wait, which don’t consume any CPU.
WorkerThread#27[10.201.1.55:56893] - priority:10 - threadId:0x00002b59983cb000 - nativeId:0x4482 - addressSpace:null - state:RUNNABLEstackTrace: java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.__AW_read(SocketInputStream.java:129) at java.net.SocketInputStream.read(SocketInputStream.java) at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at java.io.BufferedInputStream.read(BufferedInputStream.java:237) - locked (a java.io.BufferedInputStream) at java.io.DataInputStream.readByte(DataInputStream.java:248) at org.jboss.jms.server.remoting.ServerSocketWrapper.checkConnection(ServerSocketWrapper.java:94) at org.jboss.remoting.transport.socket.ServerThread.acknowledge(ServerThread.java:857) at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:585) at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:234)multicast receiver,GATES-RefData-Infinispan-Cluster,matcamupa67-vm-46719 - priority:10 - threadId:0x00002b597c1ba800 - nativeId:0x3034 - addressSpace:null - state:RUNNABLEstackTrace: java.lang.Thread.State: RUNNABLE at java.net.PlainDatagramSocketImpl.receive0(Native Method) - locked (a java.net.PlainDatagramSocketImpl) at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:145) - locked (a java.net.PlainDatagramSocketImpl) at java.net.DatagramSocket.receive(DatagramSocket.java:725) - locked (a java.net.DatagramPacket) - locked (a java.net.MulticastSocket) at org.jgroups.protocols.UDP$PacketReceiver.__AW_run(UDP.java:675) at org.jgroups.protocols.UDP$PacketReceiver.run(UDP.java) at java.lang.Thread.run(Thread.java:662)
Tool to analyze thread dumps: http://fastthread.io/.