Why wait notify and notifyAll called from synchronized

Tutorials Shared by the Internet Community

Advertisements

  Top Tutorials     New Tutorials     Submit     Login     Register  

Tutorial Detail

Why wait notify and notifyAll called from synchronized

Most of Java developer knows that wait() ,notify() and notifyAll() method of object class must have to be called inside synchronized method
http://javarevisited.blogspot.com/2011/05/wait-notify-and-notifyall-in-java.html
  • Total Hits: 12810

  • Average Rating :
    URL RatingURL RatingURL RatingURL RatingURL Rating

  •  

  • Total Votes: 140 votes

  • Category: JAVA/Core JAVA

  • Submitted on: 2011-06-27 15:10:07

  • Submitted By: Javin Paul

  • Set as Favorite

Description:

We use wait () and notify () or notifyAll () method mostly for inter-thread communication. One thread is waiting after checking a condition e.g. In Producer Consumer example Producer Thread is waiting if buffer is full and Consumer thread notify Producer thread after he creates a space in buffer by consuming an element. calling notify() or notifyAll() issues a notification to a single or multiple thread that a condition has changed and once notification thread leaves synchronized block , all the threads which are waiting fight for object lock on which they are waiting and lucky thread returns from wait() method after reacquiring the lock and proceed further. Let’s divide this whole operation in steps to see a possibility of race condition between wait () and notify () method in Java    More detail...

Rating Detail

 Stars  Percentage  Total Vote
 One star  Vote LeftVote MiddleVote Right 38.57%  54
 Two starsTwo star  Vote LeftVote MiddleVote Right 10%  14
 Three starsThree starsThree stars  Vote LeftVote MiddleVote Right 11.43%  16
 Four starsFour starsFour starsFour stars  Vote LeftVote MiddleVote Right 11.43%  16
 Five starsFive starsFive starsFive starsFive stars  Vote LeftVote MiddleVote Right 28.57%  40

Caste Your Vote

 Rating  Selection  Guidelines
 Poor:     Very disappointing, useless.
 Fair:     Below average, disappointing but not useless.
 Good:     About average in its class.
 Very Good:     Above average for its category.
 Excellent:     One of the best Tutorials in its category.






Advertisements