ए भाई Think ज़रा हटके
Note: amtyThumb must be installed for new version of amty thumb post/recent

Deadlock detection through YourKit Java Profiler

Some days ago I wrote an article How Nested Monitor can cause DeadLock and made a tracer to know what i going on in my program.

This was a simple lite-weighted tracer who monitors deadlock and exit from the program if any deadlock detected. It also prints various states of a thread. But since it is again a thread so it prints states whenever it gets proceed by CPU. Hence you miss all states of thread. YourKit Jprofiler solved this problem.

I commented deadlock detection code from tracer and run program through YourKit Profiler. Now see how this tool informed me about dead lock and various states of all running threads & CPU.

YourKit thread states

As you can see in the last, both threads A & B are blocked. YourKit popped up a deadlock message and gave me following information about deadlock.

YourKit deadlock popup

YourKit deadlock popup

It is clearly mentioned in above screen shot that which thread waiting for a lock locked by another thread. It’ll help you to debug your code. Above 2 lines explains, that thread A is taking a lock on some Integer object while thread B is taking lock on DeadLockDemo object. I’ll suggest you to override toString() of class you are locking on. It’l help you to find out exact position where a thread is locking on.

Note:

  • If you are running your program through YourKit, it takes more CPU.
  • YourKit detects deadlock after a while than Tracer. If tracer detects deadlock and exit from the program, yourkit will never know whether deadlock was occurred.


YourKit CPU time & thread overview

If you go through CPU stats, you’ll know that Thread.activeCount() & Thread.getState() takes most CPU. These method are called by tracer to know current state of thread and print it.

CPU stats

Second cycle

I dint call tracer this time and observed that CPU consumption clashed down. Dadlock was still there in the program.

CPU time and thread overview chart

Now you will not notice any Hot Spot. See how CPU consumption slashed down.

CPU time in second cycle

And here how many threads are running after skipping tracer.

Threads runninng in second cycle

Threads runninng in second cycle

Amit Gupta

Hey! this is Amit Gupta (amty). By profession, I am a Software Eng. And teaching is my passion. Sometimes I am a teacher, as you can see many technical tutorials on my site, sometimes I am a poet, And sometime just a friend of friends...

151
views


To book below area mail me




captcha

You can follow any responses to this entry through the RSS 2.0 feed.