0

I know what wait() and notify() does. But I am slightly confused by a part of definition of notify() method that I find most at the places.

Here is definition given for notify() method:

For all threads waiting on this object's monitor (by using any one of the wait() method), the method notify() notifies any one of them to wake up arbitrarily.

I was confused with the part waiting on this object's monitor.

Question : When we call obj.wait() method. Current thread releases the monitor lock. So my current thread is now not waiting on object's monitor. It is just in waiting state. As I know what does it mean by waiting state, It acknowledges Operating system to put the thread into sleep state and It keeps information of such threads into somewhere with Object(I am not sure where It stores information) So don't you think,

It is just in waiting state. not waiting on object's monitor.

I appreciate if you can help me with my understanding.

sdindiver
  • 491
  • 1
  • 5
  • 19
  • When a thread waits on an object monitor, the thread waits to obtain the intrinsic monitor lock. There is no definition as to what the thread is doing while it is blocked on monitor acuqisition. You can read more about threads and locks in [§17 of the JLS](https://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html). – Turing85 Apr 13 '20 at 07:58
  • @Turing85 According to your statement, Thread wait to obtain intrinsic monitor lock, But you have called object.wait() and any other thread has not acquired the lock, Why It is still in waiting? So don't you think It is wrong to say thread waits for obtain intrinsic lock. – sdindiver Apr 13 '20 at 08:07
  • You are confusing "waiting on the object's monitor" (after calling `obj.wait()`) with "waiting to acquire the monitor lock" (waiting to obtain the intrinsic lock): "When we call obj.wait() method. Current thread releases the monitor lock. So my current thread is now *not waiting on object's monitor*" - this last part is wrong, the current thread **is waiting** on the objects monitor,. – Thomas Kläger Apr 13 '20 at 09:24
  • FYI: https://en.wikipedia.org/wiki/Monitor_(synchronization) – Solomon Slow Apr 13 '20 at 10:42

0 Answers0