简体   繁体   中英

How to handle concurrent sql updates, given database structure can change at runtime

I am developing spring mvc application

For now I am using innodb mysql but I have to develop the application to support other databases also.

Can any one please suggest me how to handle concurrent sql update on single record.

Suppose two users are trying to update same record then how to handle such scenario.

Note: My database structure is dependent on some configuration (It can change at runtime) and my spring controller is singleton in nature.

Thanks.

Update: Just for reference I am going to implement version like https://stackoverflow.com/a/3618445/3898076 ).

Transactions are the way to go when it comes to concurrent sql updates, in spring you can use a transaction manager.

As for the database structure, as far as I know MySql does not support transactions for DDL commands, that is if you change the structure concurrently with updating, you're likely to run into problems.

To handle multiple users working on the same data, you need to implement a manual "lock" or "version" field on the table to keep track of last updates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM