a) When a
thread calls a wait(), does that release all the locks it holds or just the object on which it has called wait()? i.e. if a thread calls a synchronized method on objA (class A) and then from there it calls a synchronized method on objB (class B) and then calls wait()? At that time whether it releases the locks for objA and objB both or just objB?
b) When a thread is in wait() state and is interrupted and it throws InterruptedException, does it relases the lock? My answer is No.
c) When a thread throws an uncaught exception inside a synchronized method of a class, and so before the controls leave the current method and the exception is propagated to the next level, does the thread releases all the locks ? My answer is Yes.
I know many of you may feel these questions to be very silly but sometimes such silly questions in the exam look lot more difficult.
Thanks,
Deep