The difference between optimistic and pessimistic locking lock: Reproduced

Reprinted to: https: //blog.csdn.net/hongchangfirst/article/details/26004335

Pessimistic locking (Pessimistic Lock) , by definition, is very pessimistic, pick up data every time think others will modify, so every time she took the data will be locked, so people want to take this data will be blocked until the pending it got the lock. Traditional relational database inside to use a lot of this locking mechanism, such as row locks, table locks, read locks, write locks, are locked before doing the first operation.

Optimistic locking (Optimistic Lock) , by definition, is very optimistic, pick up data every time the thought of others does not modify the data, so it will not be locked, but when the update will determine what others during this time did not go to update this data can be used mechanisms such as the version number. Optimistic locking is suitable for the types of applications to read, so you can improve throughput.

Other kinds of locks have advantages and disadvantages, optimistic locking apply to lower write relatively few cases, namely when conflicts occur very rarely, this will save a lock of overhead, increase the overall throughput of the system. However, if the frequent conflict, the upper application will continue to be retry, such but rather reduces the performance, so use pessimistic locking is more appropriate in this case.

Guess you like

Origin www.cnblogs.com/yichengming/p/11164957.html