Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Why wait, notify, and notifyAll methods are called from synchronized block or method in Java?

Why Wait, Notify, And NotifyAll Methods Are Called From Synchronized Block Or Method In Java?
Most of the Java developers know that wait(), notify(), and notifyAll() methods of object class must have to be called inside synchronized method or synchronized block in Java but how many times we thought why? Recently this question was asked to in Java interview to one of my friend, he pondered for a moment and replied that if we don't call wait() or notify() method from synchronized context we will receive IllegalMonitorStateException in Java. He was right in terms of the behavior of language but as per him, the interviewer was not completely satisfied with the answer and wanted to explain to him more about it.


This post first appeared on Javarevisited: Blog About Java Programmin, please read the originial post: here

Share the post

Why wait, notify, and notifyAll methods are called from synchronized block or method in Java?

×

Subscribe to Javarevisited: Blog About Java Programmin

Get updates delivered right to your inbox!

Thank you for your subscription

×