cincin
cincin

Reputation: 67

notify method for two waiting thread

I am confused on one point with notify method. "notify() : It wakes up one single thread that called wait() on the same object." So lets say two thread called wait for the same object. So when I call notify which thread will be notified?

Upvotes: 0

Views: 25

Answers (1)

Grisha Levit
Grisha Levit

Reputation: 8617

You can't know which one will be notified. Spec says:

public final void notify()

Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation.

Upvotes: 1

Related Questions