We have implemented a multi threaded application for updating a column of the table in database
ie, user account balance. The hibernate is used for interacting our application with data base. The application is deployed in multiple servers and will be worked as a cluster.
suppose the multiple requests are sent for updating the same user account in database. how can we handle this situation? The request from multiple servers or different threads from same server will try to update this at the same time. how can ensure the atomicity of the operation. can we do the same by data base -table or row- level lock using hibernate or spring framework
Example :
thread A from server S1 and thread B from server S2 access the same record R at the same time.
First the thread A from server S1 update the value of R to R1 and commit the transaction.
At the same time the thread B from server S2 update the value of R to R2 and commit the transaction.
what will be the outcome of this scenario?. we have to lock one of the transaction for the right results?. how can we lock the transaction because it is came from different servers?.