Java: waiting on synchronized block, who goes first?

后端 未结 4 1486
青春惊慌失措
青春惊慌失措 2020-12-06 10:30

This question is inspired by this other question.

If multiple threads are waiting on a synchronized block, and the lock becomes available, who goes firs

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 11:15

    It depends on thread priority and thread scheduling algorithm and also the lock on the synchronized block is not "fair". This means that if there are 2 waiting threads with the same priority and the first thread waited more than the second thread that doesn't necessarily mean that the first thread will be executed first.

提交回复
热议问题