Hi Rohan,
Even if in a synchronized block when a thread acquires a lock on a third party object and finishes executing a synchronized method of that object(effectively dropping the lock), another thread cannot enter the synchronized block till the first thread leaves the block?
It seems to me, you are drawing some conclusion in the suspicious
way. "third party" means?
SyncTest Has-A NewThread so object of NewThread is soul part of
the SyncTest. You are creating only one object of SyncTest as "PayLoad"
and two launchers (threads) are there. In one method you have lock on
the nt (NewThread) and because there is only one SyncTest object, both
threads will behave gently, working one after one. What monitor you are using is member of the instance st(SyncTest object created in the main()).
So therfore after and only after one thread finishes it job or say comes out
of the critical section, leaves the monitor, then another thread can enter
that section.
With Regards,
cmbhatt