Java: How to distinguish between spurious wakeup and timeout in wait()
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 (dosleep){ try { wait(2000); /** * Write some code here so that * if it is spurious wakeup, go back and sleep. * or if it is timeout, get out of the loop. */ } catch (InterruptedException e) { e.printStackTrace(); } } In this case how can I distinguish between a spurious wake up and time out? If it is a spurious wake up, i need to go back and wait. And if it is a timeout, i need to get out of the loop. I can easily identify the case of notify(