You have to have to lock on an object to call notify -- i.e.,
synchronized (someObject) {
someObject.notify();
}
Now, think about it. The threads that are awoken by notify() can't get the lock until this synchronized block release it. See? Because you can't call notify() unless you're actually holding the lock on the object.
Now when you call wait(), you also have to have the lock. When you call wait(), it gives up the lock. Then when someone calls notify(), this
thread may then reaquire the lock and wait() can return. wait() can't return until it has the lock.
[ July 27, 2003: Message edited by: Ernest Friedman-Hill ]