SCJP, SCWCD, SCBCD, SCEA 5
You really want the Consumer to wait until the Producer puts something in the CubbyHole and the Producer to notify the Consumer when it's done so. Similarly, the Producer should wait until the Consumer takes a value (and notifies the Producer of its activities) before replacing it with a new value. The two threads must coordinate more fully and can use Object's wait and notifyAll methods to do so.
SCJP, SCWCD, SCBCD, SCEA 5
So basically wait, notify and notify all is a matter of convienience from the developer point of view to improve performance by making other threads not checking the status of locks till they have been notified by the lock holding thread.
Am I right?
In my case this locking contention by other threads can happen only once during the whole day like (5.00 in the morning) as standing data will be refreshed once.
Critical Sections:
isRefreshRequired(Consumer)
RefreshCache(Producer).
I did not bother about wait, notify and notify all. Now Ideally I just have to sync both the above methods, as this is code is present as a part of every request i just have sync on producer method and let consumer call producer more than once based on the number of thread concurrency at the time but i dont want all threads to run producer at the same time.
Should be fine I gues your opinion?
Regards
Farouk
Consider Paul's rocket mass heater. |