Here's the setting: the entity class has a collection of other objects that load lazily. The trick is that I need to do some work related to the data (for example, I want to calculate a certain checksum with the elements of the collection).
The trick here is that I want to avoid race conditions at all costs, such as: "someone updated the object while I was doing calculations with the data." Under normal circumstances, I simply declare that getter / setter is in sync and will be happy with it. BUT, as I understand it, if another thread decides to update the state of the entity from the database, while I am in the middle of calculating my checksum, it completely ignores the "synchronized" methods (it will directly access the field).
Maybe I'm wrong. Thus, the question arises: is there a way to “block” access to part of the object or to the whole entity during the initial checksum calculations?
Thanks in advance! Postscript If you need a piece of code to illustrate the problem, just let me know. So far, I think the question is pretty clear.
Juriy source
share