• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

notifyAll()

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does notifyAll() only notify threads synchronized on the same lock as the context that notifyAll() was called from?

So a thread that is waiting that was synchronized on another object's lock will not return to runnable when notifyAll() is called from a thread that is synchronized on a different objects lock?

Am I making sense?
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joshua Fix ,

can you please give your question little bit clear...

Thanks,
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
notify and notifyAll will wake up one or all threads which are in the
threat-waiting pool of the object whose notify(all) methode is called.

Your question is a little confusing:
in generall, i wouldnt say "a thread is synchronized" but instead "one or more method(s) (and therefore the data accessed by this method(s) are synchronized".

to call wait on an object, a thread has to have the objects lock, which it will gain by entering a method synchronised on this object.

If now wait() is called on this object, the object`s lock is set free again for other threads and the thread calling wait is in the objects waiting pool.

Now, if an other thread gets the lock on this object, it is able to call notify on this object and therefore wake up the thread described above.

threads waiting in the waitong pool of other objects are not influenced

I hope this is helpfull
 
Joshua Fix
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies... here's some code I used to test my question:




My question was, does the call to nc.notifyAll() notify f to return to runnable and print "finished waiting". Looks like a simple test answered my own question. I had to have a block of code synchronized on "f" that calls notifyAll(). Only when I remove the commented code do I see the text "finished waiting".
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic