The multi-threaded optimistic pessimistic locking

Optimistic locking: that the data modification probability of conflict is not large, so it will not acquire the lock first, generally used to mark a version number or timestamp, if A and B simultaneously modify the data, when A modification is completed at the same time stamp replace also make changes to the time stamp, then you will find the entry data has been modified, it can not be modified when the B to B modified

  Advantages: data is not locked, will only be verified without impacting server performance when the data modification operations for more business scenarios inquiry

  OK: because it is used to artificially manipulated, if there are remaining non-human handling things mixed with some errors might occur

Pessimistic lock: that the data appears regularly change, acquires a lock before it is modified using the remaining things so that data can not be modified

  Advantages: use pessimistic locking locking mechanism to implement data in the database changes the order of execution, the locking specified data row, is adapted to modify more frequent application scenario

  The disadvantage is: Once locked, other things can not lock data, all operations except the query, if the current execution cycle of things longer, something else will have to wait, affect performance.

Guess you like

Origin www.cnblogs.com/huayuxiaoxiang/p/11232478.html