In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Optimistic lock
Optimistic locks are not included in the database and need to be implemented by ourselves. Optimistic lock refers to the operation of the database (update operation), the idea is very optimistic, that this operation will not lead to conflict, in the operation of the data, there is no other special processing (that is, no lock), and after the update, to determine whether there is a conflict.
The implementation usually goes like this: when the data in the table is manipulated (updated), add a version field to the data table first, and add 1 to the version number of that record each time you operate. That is, first query the record and get the version field. If you want to operate on that record (update), first determine whether the value of version is equal to the value of version when you just queried. If it is equal, it means that there are no other programs operating on it during this period, then you can update it and add 1 to the value of the version field. If it is found that the current version value is not equal to the version value just obtained during the update, it means that other programs have operated on it during this period, and no update operation will be carried out.
Pessimistic lock
Corresponding to the optimistic lock is the pessimistic lock. Pessimistic lock means that there will be data conflicts when operating data, so it is necessary to acquire a lock to operate on the same data every time. This is very similar to synchronized in java, so pessimistic locking takes a lot of time. In addition, corresponding to the optimistic lock, the pessimistic lock is realized by the database itself. when we want to use it, we can directly call the relevant statements of the database.
At this point, there are two other lock concepts involved in pessimistic locks, namely shared locks and exclusive locks. Shared lock and exclusive lock are different implementations of pessimistic lock, and they both belong to the category of pessimistic lock.
Summary:
Optimistic Lock-- Program-side implementation
Pessimistic Lock-- Database self-implementation
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.