Pessimistic concurrency and Optimistic Concurrency

Source: Internet
Author: User

To put it simply:

Optimistic Concurrency means that when writing a database, it is assumed that there will be no conflict, and then it will be processed when there is a conflict.
Pessimistic concurrency means that errors always occur when writing data to the database. Therefore, we need to compare the Field Values Before updating.

Details:

Optimistic Concurrency: In optimistic concurrency control, data is not locked when users read data. When an update is executed, the system checks whether the data has been changed after another user has read the data. If another user updates the data, an error occurs. Generally, the user who receives the error message will roll back the transaction and start again. This method is mainly used in environments with less data competition and in which the cost of occasionally rolling back transactions exceeds the cost of locking data when reading data. Therefore, this method is called optimistic concurrency control.

Pessimistic concurrency: the locking system prevents users from modifying data in a way that affects other users. If a lock is applied because of the operation performed by the user, other users cannot perform operations that conflict with the lock until the lock owner releases the lock. This method is mainly used in environments where data competition is fierce, and when concurrent conflicts occur, the cost of using locks to protect data is lower than the cost of rollback transactions, therefore, this method is called pessimistic concurrency control.

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.