Pessimistic locking a record or page get locked immediately - Database

Q.  Which type of lock does a record or page get locked immediately?
- Published on 26 Aug 15

a. Pessimistic locking
b. Optimistic locking
c. Both A & B
d. None of the above

ANSWER: Pessimistic locking
 

    Discussion

  • Nirja Shah   -Posted on 03 Nov 15
    - A lock, as a read lock or write lock, is used when multiple users need to access a database concurrently.

    - It prevents the data from being corrupted or invalidated when multiple users try to read while others write to the database.

    - There are two mechanisms for locking data in a database: pessimistic locking, and optimistic locking.

    Pessimistic locking
    - It is a record or page that is locked immediately when the lock is requested.

    Optimistic lock
    - The record or page which is only locked when the changes made to that record are updated.

    - The latter situation will be appropriate only when there is less chance of someone needing to access the record while it is locked; otherwise it cannot be certain that the update will succeed because the attempt to update the record will fail if another user updates the record first.

    - With pessimistic locking it is guaranteed that the record will be updated.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)