Java Thread wait() => blocked?

前端 未结 6 675
北荒
北荒 2020-12-28 09:55

According to Java thread state info calling wait() will result a thread to go in BLOCKED state. However this piece of code will result (after being called) in a Thread in WA

6条回答
  •  伪装坚强ぢ
    2020-12-28 10:06

    Just as a reminder, you should always call wait() inside a while loop waiting on the condition for entering the synchronized region/critical section. This is because Java has "spurious wakeups" (essentially, a thread can wakeup at any moment for no reason).

提交回复
热议问题