Google News
logo
Java Multithreading - Interview Questions
Why wait and notify method are called from synchronized block?
wait() is called, so that thread can wait on some condition. When condition is met, then thread has to give up the lock.
 
To give up the lock, thread has to own it first. Thread can acquire lock by enter into synchronized context.
 
If wait method is called outside of synchronized context, then it will throw IllegalMonitorStateException.
Advertisement