Sinsing analysis of optimistic lock and pessimistic lock

Source: Internet
Author: User

There is a netizen asked me optimistic lock and pessimistic lock related issues, so to explain this problem. First of all, the optimistic lock, it is pessimistic lock shorthand, that is, the so-called pessimistic lock. It is thought that someone else will modify its data every time the data is taken, so it is locked before each data fetch, so that when someone takes the data, they must wait until it releases the lock. In fact, our relational database uses a lot of this locking mechanism, such as row locks, table locks, write locks, and so on, are the first to add a lock before the operation.

The so-called optimistic lock, is the abbreviation of optimistic lock, also known as the optimistic lock. Every time it takes the data to think that others will not change the data, so it will not lock, but in each update will be to determine the time when others have not updated this data, it can be implemented using a multi-version mechanism. Optimistic locking is often used for applications with multi-read operations, which can greatly improve throughput. Reading locks, for example, are usually optimistic locks.


Maybe someone will mention MVCC, in general, MVCC is an optimistic lock implementation, in fact, is the main way to achieve. Therefore, in general, we can call the non-MVCC implementation of the lock is pessimistic lock, and through the MVCC implementation of the lock, called optimistic lock.

What's more, the optimistic lock and MVCC are directly equated, so it is not strictly appropriate, after all, MVCC is the way of realization, and optimistic lock is the concept of lock, the two are not conceptual equivalence.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Sinsing analysis of optimistic lock and pessimistic lock

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.