Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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: 23912
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic