Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Steve
Prem Vinodh wrote:Hi Anayonkar Shivalkar/Steve Luke,
Thanks for the wonderful help your'll are providing me.
I got what your'll meant but I still have further questions.
@Anayonkar Shivalkar
Yes I believe it makes sense to me now to synchronize both the readBalance() and updateBalance() methods to get consistent values.
But I also just wanted to know if there are no threads performing updates to the balance field then the method readBalance() which if synchronized will have to execute one thread at a time (assuming there are 10 threads all trying to execute the readBalance()) which would be unnecessary.
How do I cope with this scenario?
@Steve Luke
Thanks Steve for broadening my views that I need to think in others directions too.
Otherwise I would have made the mistake of assigning intermediate values to the balance field and henceforth will keep in mind atomicity too.
And I have one last question, is synchronizing both readBalance() and writeBalance() methods a scaleable solution?
Please do let me know.
Steve
Consider Paul's rocket mass heater. |