问题描述:

As my understanding, if I am thread then:

  • When I call notify()/notifyAll() it means means I am sending a signal to other thread which

    are waiting on this object monitor. Am I right?

  • But What the wait() means?

    Am I sending signal to other thread to wait so that I can complete my work on it?

    Or

    I am declaring that I will wait, You do your work and tell me when you are done.?

I have a little concept about threads

网友答案:

No, it means you want to wait for a notification.

As per the Java docs (my emphasis):

Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

网友答案:

It means "I am declaring that I will wait, You do your work and tell me when you are done."

Document Says,

Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0). The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

See this link

相关阅读:
Top