Jiger,
You are correct and the mock exam is wrong.
I wrote a code to prove that sleep() does not release the lock. It instantiates two
thread. Each thread will enter a synchronized method (requiring a lock on the object), and will be put to sleep for 5 seconds. If the lock is release, then the second thread should be able to execute the same method almost immediately. The output shows that this is not the case.
Opps...Forgot the output:
Going to sleep for 5000 msecs. Thread-0 981870062930
Waking up from sleep: Thread-0 981870068030
*****************************************************
Going to sleep for 5000 msecs. Thread-1 981870068030
Waking up from sleep: Thread-1 981870073030
*****************************************************
Notice that Thread-0 sleeps and wakes up before Thread-1 gets a chance to enter the synchronized method.
-Peter
[This message has been edited by Peter Tran (edited February 10, 2001).]
[This message has been edited by Peter Tran (edited February 10, 2001).]