One minute teaches you the difference between optimistic locks and pessimistic locks

Source: Internet
Author: User

The pessimistic lock, as its name implies, is very pessimistic. Every time you get the data, you think someone else will modify it. So every time you get the data, you will lock it, in this way, others will block the data until it gets the lock. In traditional relational databases, many of these locks are used, such as row locks, table locks, read locks, and write locks.


Optimistic lock, as its name implies, is optimistic. Every time you get the data, you think that others will not modify it, so they will not lock it, however, during the update process, the system determines whether someone else updates the data during this period. You can use the version number and other mechanisms. Optimistic locks apply to multiple read application types, which can improve throughput,If a database provides a mechanism similar to write_condition, it actually provides optimistic locks.


The two locks have their own advantages and disadvantages and cannot be considered better than the other. For example, optimistic locks apply to the case where there are few writes, that is, when a conflict is rare, this saves the lock overhead and increases the overall throughput of the system. However, if there are frequent conflicts, the upper-layer applications will constantly retry, which reduces the performance. Therefore, it is more appropriate to use pessimistic locks in this case.

Original article: http://blog.csdn.net/hongchangfirst/article/details/26004335

Author:Hongchangfirst

Hongchangfirst home: http://blog.csdn.net/hongchangfirst


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.