Reputation: 537
What happens to waiting thread if notify() is not called? Is this spurious wakeup?
Upvotes: 7
Views: 1865
Reputation: 51721
If a waiting Thread
is not notified by calling notify()
or notifyAll()
on the object the said thread is waiting on, then any one of the following may happen:
Thread
keeps waiting in the object's wait poolThread
becomes runnable if a timeout was specified and the time elapsesThread
gets interrupted and becomes runnable againThread
wakes up for no reason at all i.e. it was neither notified nor interruptedThe last case is known as a spurious wake-up and is one of the reasons why upon wake-up a Thread
should always check whether the condition it was waiting for is true or not. If not, the Thread
should call and go wait()
again.
Upvotes: 11