obtaining instrinsic lock means the
thread has acquired the monitor of the object. no thread can acquire the same montior until it is released.
if you use wait/notify, here is the code snipet
what it does is first acquire the monitor, put itself on wait for the notification, then release the monitor. And once it is notified, the thread will aquire the monitor first before it can execute methodA and methodB. and after the whole is executed and exited, the monitor is released.
for await use case;
ReentrantLock lock;
Condition notEmpty = lock.newCondition();
Condition otherCondition = lock.newCondition ();
...
lock.lock ()
try
{
notEmpty.await ();
..
}
finally
{
lock.unlock ();
}
similar sequence as wait, but you can have different conditions created for the same lock.
to notify a wait, you use notify.
to notify a condition.await, you use condition.signal.
also, most of the time, people use a spin lock during the wait to avoid race condition
hope this help.....