Grokking Java Interview Questions
0% completed
wait, notify, and Guarded Blocks
A method can sometimes continue only when an object has a certain state, such as a stock of at least 30 mangoes. The thread can then give up the lock and stop running until another thread has created that state. Code that checks a condition and waits until it is true is called a guarded block, and Java supports it with the methods wait(), notify(), and notifyAll() of the class Object.
The sections below follow one waiting thread from the check to the wakeup, explain why the check is a loop, compare wait() with sleep(), and show a program in which `notify()
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%