Pessimistic vs Optimistic locking

Pessimistic locking: When we lock the record exclusively for our exclusive use until we have finished it. The disadvantage is that a resource is locked from the time it is first accessed in a transaction until the transaction is finished

We can go for this locking mechanism in case of more conflicts or transactional systems. eg: database locking.

Optimistic locking: With this locking, a resource is not actually locked when it is first accessed by a transaction. Here we read a record, take note of a version number and check that the version hasn't changed before we write the record back.

We can go for this locking mechanism in case of less conflict. eg: Wikipedia update.

Correct me if anything is wrong.


要查看或添加评论,请登录

Sandeep Singh的更多文章

  • Pocket guide for the coding round...

    Pocket guide for the coding round...

    Step1: Learn and practice below Data structure and algorithms. Analyze time and space complexity.

    1 条评论
  • have you ever thought about how important DSA is...

    have you ever thought about how important DSA is...

    The programmer must be having a question that why should I study DSA if it has no use in real life? Why do Tech…

    11 条评论
  • Misleading Phrase: Kubernetes vs. Docker/Which one is better

    Misleading Phrase: Kubernetes vs. Docker/Which one is better

    The phrase, “Kubernetes vs Docker?” in itself is rather absurd, like comparing apples to oranges. Docker is like an…

    5 条评论
  • We have openings in Visa

    We have openings in Visa

    We are hiring Staff Engineer . Experience from 7 yrs to 14 years Key Skills : Java, Data Structure, Algorithm,Spring…

社区洞察