High CPU Utilization in java application - why?

Jasper picture Jasper · Apr 4, 2013 · Viewed 102.9k times · Source

I have a Java Application (web-based) that at times shows very high CPU Utilization (almost 90%) for several hours. Linux TOP command shows this. On application restart, the problem goes away.

So to investigate:

I take Thread Dump to find what threads are doing. Several Threads are found in 'RUNNABLE' state, some in few other states. On taking repeated Thread Dumps, i do see some threads that are always present in 'RUNNABLE' state. So, they appear to be the culprit.

But I am unable to tell for sure, which Thread is hogging the CPU or has gone into a infinite loop (thereby causing high CPU util).

Logs don't necessarily help, as the offending code may not be logging anything.

How do I investigate - What part of the application or what-thread is causing High CPU Utilization? - Any other ideas?

Answer

ericson picture ericson · Apr 4, 2013

If a profiler is not applicable in your setup, you may try to identify the thread following steps in this post.

Basically, there are three steps:

  1. run top -H and get PID of the thread with highest CPU.
  2. convert the PID to hex.
  3. look for thread with the matching HEX PID in your thread dump.