For data that is regularly updated, you must put a lock on the data in the cache before using the data in an operation. The lock prevents race conditions (two or more operations attempting to update the same data at the same time). Other operations are then prevented from changing the data in the cache until the first operation is complete, and the lock is removed.
In the following example code, the operation simulates the purchase of a fund from an account.
Note To keep the code simple, the account balance is read from local data as if it was free from race conditions. In a real situation, the data would be read from the cache and would require a lock.
public boolean executeOperation() throws Exception {