Sandeep Kumar B wrote:
I was expecting that since in the loop sleep(100) is more than wait(1), wait statement would stop waiting and print the Total in the middle of the calculation
but after wait period i.e. 1 miliseconds is over main thread will have to reacquire the lock on ThreadB object b,
so it will block for lock on b to be released, sleep() method call in ThreadB does not cause lock to be released,
so lock of b is still with ThreadB.
Joined: Apr 17, 2011
I do not know what are you trying to achieve. the current behavior is because sleep blocks but doesn't give up monitor. Thus the other thread doesn't get the monitor and doesn't executes.