The following sections provide information on how to troubleshoot various problems that may arise for deployment in production environments.
Analyzing a stack trace
When your Java process starts to spin your CPU, you must immediately analyze the issue using the following two commands and obtain the invaluable information required to tackle the issue. This is done based on the process ID (pid).
jstack <pid> > thread-dump.txt
ps -C java -L -o pcpu,cpu,nice,state,cputime,pid,tid > thread-usage.txt
Tip: OS X users can alternatively use the command
ps M <PID>instead.
These commands provide you with the thread-dump.txt file and the thread-usage.txt file. After obtaining these two files, do the following.
Find the thread ID (the one that belongs to the corresponding PID) that takes up the highest CPU usage by examining the thread-usage.txt file.
In this example, the thread ID that takes up the highest CPU usage is 1604.
- Convert the decimal value (in this case 1604) to hexadecimal. You can use an online converter to do this. The hexadecimal value for 1604 is 644.
- Search the thread-dump.txt file for the hexadecimal obtained in order to identify the thread that spins. In this case, the hexadecimal value to search for is 644. The thread-dump.txt file should have that value as a thread ID of one thread.
That thread usually has a stack trace, and that's the lead you need to find the issue. In this example, the stack trace of the thread that spins is as follows.