Hi Prasad,
In this program you have two threads , main
thread and b. After starting b thread , main goes to sleep.
Now b thread get chance to execute . It calls run method and doTask2() method , where it acquires lock of object a
and joins main thread . Due to this, thread b goes in block state with lock of object a .
Now when main thread come out of sleep state . It try to call doTask1() method on object a , but because this method is synchronized , it needs lock of object a , but lock is not available, because it is with thread b.
So both threads now in block state.
Hope it will help you