In the classic producer comsumer examples used in many books when explaining Synchronization, the Synchronized methods always begin with a while loop that checks a condition and then calls the wait() method.
When that
thread gets notified by another thread, where does the waiting thread resume execution from? Does it beging at the beginning of the synchronised method or at the line just after the wait() method ?
What is the reason for using a while loop and not an if statement to check if it is OK to produce or consume?
If there are multiple threads waiting and all of them get notified, do they all become "Ready" and then wait for the scheduler to allow one of them to run? At what point does a thread that became ready to run, starts to process the Synchronized method?
What happens to all the other threads that became
"Ready" when they were notified?
Thanks