• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Superfluous notifyAll() Good Programming Practice?

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your code synchronizes on an object (myObject) and, at the time you are writing the code, there is currently no thread that calls myObject.wait(), is it still good programming practice to put notifyAll() at the end of all your synchronized blocks in anticipation of future code calling myObject.wait() ?
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMO,it is not a good idea. You wait() because you need a condition to exist. You notify() when the condition exist... Whatever this condition is, in the future, I am willing to bet that it is not because you are about to exit a synchronized block.

Henry
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
synchronizing and waiting are different things. you dont wait because you cant access a synchronized block of code. You wait for some logical reason, like the bus has not arrived yet or its not 5pm yet. synchronizing and waiting are totally different concepts. Though to wait you will need to use synchronization.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic