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.

----------------------------------------------------------------------------------------------
Source: https://blogs.oracle.com/jiechen/entry/analysis_against_jvm_thread_dump

Monday, May 26, 2014

To get http status code from curl call


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

We can use below command to get http response code of a URL from bash script.

status_code=$(curl --write-out "\n%{http_code}\n" --silent --output /dev/null --insecure https://www.google.co.in/)

silent - to stop progress information in output
output - we are re-directing normal output to null device
write-out - whatever things we needed can be given here. Here we are printing http status code. It will be printed after completion, i.e., after printing all output.
insecure - this allows connections to SSL sites without certs

References: http://stackoverflow.com/a/2220646/324900

Latest Posts