0

If I use synchronised methods or locks and some threads enter wait queue, do they leave the wait queue in same order as they entered it? In other words, does the first thread to enter wait queue also leave it first?

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
Rohit Malish
  • 3,209
  • 12
  • 49
  • 67

1 Answers1

0

No, the JVM chooses randomly a Thread to wake from waiting state either one uses notify() or notifyAll() to wake them. In particular with notify() only one Thread will randomly be chosen to enter the excecution state, while with notifyAll() all the waiting Threads together, but there is no guarantee in what order will they be excecuted.

arjacsoh
  • 8,932
  • 28
  • 106
  • 166