For the following code notifyAll() will hold the lock until done, even when the timeout has reached, this block doesn't hold the lock and has to wait for the notifyAll() block to be finished. Then what's the meaning of the timeout in wait(timeout) if after the timeout is done we still have to wait for the lock? Also - how to change the code so that the timeout will have meaning?
// one thread
synchronized (lock) {
lock.wait(timeout);
}
// second thread
synchronized (lock) {
// do some processing actions.......
lock.notifyAll();
}