important! note you know the number of CPU X Cores in your server cat /proc/cpuinfo
Identifying which Java Thread is consuming most CPU
I didn’t come up with this. I was shown how to do this by an esteemed college at work.
Most (if not all) productive systems doing anything important will use more than 1 java thread. And when something goes crazy and your cpu usage is on 100%, it is hard to identify which thread(s) is/are causing this. Or so I thought. Until someone smarter than me showed me how it can be done. And here I will show you how to do it and you too can amaze your family and friends with your geek skillz.
monitoring in production (and other envs...)
* run top
* press Shift-H to enable Threads View
* get PID of the thread with highest CPU
* convert PID to HEX
* get stack dump of java process
* in stack dump look for thread with the matching HEX PID.
see tomcat tuning book
see java profiling and tuning book.