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() ?
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.
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.
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss