ObjectiveTo understand the basics of how a high cpu thread can be identified in a Java application.
- There are many good articles in net which tell step by step instructions to identify a high cpu thread in a Java application running on different OS. In this article I just try to summarize the key concepts instead of walk you through the steps/examples.
- The Linux OS have one to one mapping between Java (version 1.2 onwards) threads and OS threads, and the easiest way to identify a high cpu thread is:
- Run command: top -H
- The output of above command will be PID (thread id) sorted in descending order of CPU usage.
- Once you get the PID of high cpu thread (probably you need to monitor the high CPU thread for some time to see if it is keeping the CPU usage high for some longer time), take a thread dump of your Java application (via jstack or any other profiling tool lie VisualVM).
- The PID you got has to be converted into Hexa number before you search that into thread dump to identify which Java thread in your application it is and with the stack trace in dump you will be able to identify what kind of task the thread is doing.