0

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?

cincin
  • 67
  • 1
  • 7
  • Possible duplicate of [Java: notify() vs. notifyAll() all over again](http://stackoverflow.com/questions/37026/java-notify-vs-notifyall-all-over-again) – ravthiru Jan 23 '17 at 01:03

1 Answers1

1

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.

Grisha Levit
  • 8,194
  • 2
  • 38
  • 53