Data Access Mode: data concurrency control)

Source: Internet
Author: User

1. Introduction to data concurrency control

Data concurrency control is a system used to process multiple modifications to persistent business objects at the same time point. When multiple users modify the state of the business object and try to persistently store it to the database concurrently, a mechanism is required to ensure that one user does not have a negative impact on the transaction state of another concurrent user.
There are two forms of concurrency control: optimistic and pessimistic. Optimistic Concurrency Control assumes that when multiple users modify the Business Object status at the same time, it will not cause any problems, also known as the last change wins ). This is a reasonable action for some systems. However, if the state of the business object needs to be consistent with the State retrieved from the database, pessimistic concurrency control is required.
Pessimistic concurrency control can have multiple styles. You can lock the data table After retrieving the records, or save copies of the original content of the business object, before updating, compare the copy with the version in the data storage. Make sure that the record is not modified during this transaction.

2. Example of data concurrency control

There are two common methods to implement data concurrency control: database implementation and code control implementation. Pessimistic concurrency control can be added to the database lock mechanism in terms of database implementation. In terms of code control implementation, a save version number field can be added for comparison between versions. Use the version number to check whether the business entity is modified after it is retrieved from the database. When updating, compare the version number of the business entity with the version number in the database before submitting the modification. This ensures that the business entity is not modified after it is retrieved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.