Monday, November 3, 2014

Find out which Java thread is causing the high CPU usage

Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart

You see your java application is consuming high CPU but you don't know specifically which thread is consuming CPU out of thousand threads.

The solution is very simple.
1. First we need to find out native thread ID that is using high CPU. Issue top -H command on terminal and it will show all threads and the percentage of the CPU they are consuming. Find out your application thread from the list and note down native thread id which will be shown in the first column named PID.

2. Take thread dump of your application.

3. Thread dump contains native thread ID but in hexadecimal format. So convert the decimal thread ID we have noted in the first step to hexadecimal value and search for this value in the thread dump and you will find the thread's stack trace.

 You can see more detailed explanation in the source link below. It gives an example program and also details how to do this in both Unix and Windows.


No comments:

Post a Comment

Latest Posts