Hi,
I am going through a java 6 book. A sample code snippet is given below from Threads chapter, where I need a clarification
synchronized(a){ //The thread gets the lcok on 'a'
a.wait(2000);// Thread releases the lock and waits for notify only for maximum of two seconds, then goes back to runnable state
//The thread reacquires the lock
//More instructions here
}
Now my doubt is, after 2 seconds of wait time, to continue further code execution, the above code would require the lock on object 'a' and there is fair chance that the other thread (which is supposed to call notify() on a) might already be holding a lock on it.
So shouldn't the thread go to Blocking state after 2seconds wait, instead of Runnable state as mentioned above in the comments (in Line No. 2).
Kindly clarify what am I missing here.
Thanks & Regards, Harish