Java: How to distinguish between spurious wakeup and timeout in wait()

前端 未结 3 1607
情书的邮戳
情书的邮戳 2020-12-10 15:37

Here is a case where a thread is waiting for notify() or a timeout. Here a while loop is added to handle spurious wake up.

boolean dosleep = true;
while (do         


        
3条回答
  •  青春惊慌失措
    2020-12-10 15:46

    I believe Locks and Condition will better fit your need in this case. Please check the javadocs for Condition.awaitUntil() - it has an example of usage

提交回复
热议问题