Hello guys,
Here's the setup: the entity class has the collection of other entities that is loaded lazily. The trick is, I need to perform some data-related work (for example, I want to calculate certain checksum with the elements of collection).
The trick here is that I want to avoid at all costs the race conditions like: "someone has updated the entity while I was making my data calculations". In the normal circumstances I'll just declare getter/setter synchronized and will be happy with it. BUT as far as I understand, if the other thread decides to update the entity state from the database, while I'm in the middle of calculating my checksum it will completely ignore the "synchronized" methods (it will access the field directly).
I might be wrong tough. So the question is: is there any way to "lock" the access to the part of the entity or to the whole entity itself for the time of initial checksum calculations?
Thanks in advance! P.S. If you need a code snippet to illustrate the problem - just let me know. So far I think the question is pretty clear.