Let us imagine each operation is done in a time frame of one second.
Second1 : "Friend" object for "alphonse" is created
Second2 : "Friend" object for "gaston" is created
Second3 : "bow()" method is called by "alphonse" and this will run in an individual thread
Second4 : "bow()" method is called by "gaston" and this will run in an individual thread
Second5 : "bowBack()" method is called by both "alphonse" and "gaston" objects at the same time. Since, "bowBack()" is a synchronized method, only one instance of that method can run at a time. So, if two objects call a synchronized method approximately at same time, each thread will wait for another thread to finish its job with the synchronized method "bowBack()". This waiting will last for ever and is called as DeadLock.





by: a_bPosted on 2009-11-04 at 20:34:59ID: 25746800
It's because they are in a deadlock, waiting for each other to finish. Try executing this -
Select allOpen in new window