• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How the state transition takes place when notify or notifyall is called?

 
Greenhorn
Posts: 12
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to know what happens when notify and notifyall is called on an object.
I read from some blog that when notify() is called only one thread out of many which called the wait() on the object is made awake from WAITING state and made RUNNABLE directly and when notifyall() is called then all the threads which called wait() are made awake but only one choosen by JVM scheduler and shifted to RUNNABLE state and others in BLOCKED state and not in WAITING state.
Please let me know.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

BadriNath Ojha wrote:I wanted to know what happens when notify and notifyall is called on an object.
I read from some blog that when notify() is called only one thread out of many which called the wait() on the object is made awake from WAITING state and made RUNNABLE directly and when notifyall() is called then all the threads which called wait() are made awake but only one choosen by JVM scheduler and shifted to RUNNABLE state and others in BLOCKED state and not in WAITING state.
Please let me know.



Correct. Calling the notify() method will wake up one of the threads, that is waiting on the object, and put it in the block state (as it needs to reacquire the synchronization lock). Calling notifyAll() does that to all the threads waiting on the object.

Once a thread reacquires the synchronization lock, it becomes runnable, and can return from the wait() method.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic