assuming that you are talking about the while loop starting at line 26, have you read carefully the explanation given in K&B:
In practice this doublecheck
is probably not necessary, as the only time a notify() is ever sent is when a
new job has been added to the list. However, it's a good idea to require the thread to
recheck the isEmpty() condition whenever it's been woken up, because it's possible
that a thread has accidentally sent an extra notify() that was not intended.
There's also a possible situation called spontaneous wakeup that may exist in some
situations—a thread may wake up even though no code has called notify()
or notifyAll(). (At least, no code you know about has called these methods.
Sometimes the JVM may call notify() for reasons of its own, or code in some other
class calls it for reasons you just don't know.) What this means is, when your thread
wakes up from a wait(), you don't know for sure why it was awakened. By putting
the wait() method in a while loop and re-checking the condition that represents
what we were waiting for, we ensure that whatever the reason we woke up, we will
re-enter the wait() if (and only if) the thing we were waiting for has not happened
yet. In the Machine class, the thing we were waiting for is for the jobs list to not be
empty. If it's empty, we wait, and if it's not, we don't.
Doesn't it explain well the purpose of that while?