Java: waiting on synchronized block, who goes first?

Thilo picture Thilo · Oct 15, 2010 · Viewed 8.6k times · Source

This question is inspired by this other question.

If multiple threads are waiting on a synchronized block, and the lock becomes available, who goes first? Is it by thread priority (and then first-come-first-served)?

And do the same rules apply for notify (with multiple waiting threads)?

Answer

Mikkel Gadegaard picture Mikkel Gadegaard · Oct 15, 2010

According to this guy: http://tutorials.jenkov.com/java-concurrency/starvation-and-fairness.html

Java issues no guarantees about the sequence. So I guess it is not based on thread priority

I'll try to look further for an explanation on how Java actually decides who goes first.