How can the wait()
and notify()
methods be called on Objects that are not Threads? That doesn\'t really make sense, does it?
Surely, it mus
You can use wait()
and notify()
to synchronize your logic. As an example
synchronized (lock) {
lock.wait(); // Will block until lock.notify() is called on another thread.
}
// Somewhere else...
...
synchronized (lock) {
lock.notify(); // Will wake up lock.wait()
}
with lock
being the class member Object lock = new Object();