Java: waiting on synchronized block, who goes first?

后端 未结 4 1483
青春惊慌失措
青春惊慌失措 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:07

    for your second Question

    one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods.

    From http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#notify()

提交回复
热议问题