Concurrency allows us the simultaneous access of same data by different users. The process of managing simultaneous execution of transactions in a shared database, to ensure the serializability of transactions, is known as concurrency control. It avoids the adverse effect of one transaction to another transaction. These are of two types.
Pessimistic concurrency control: It assumes when a conflicts happen. This technique detects conflicts as soon as they occur and resolve them using locking. The system lock prevents users from modifying data in a way so that it will not affect other user. After a user performs an action that causes a lock to be applied, so that other users cannot perform any action on that.
Optimistic concurrency control: This is called optimistic because the conflicts between transactions are rare and it doesn't require locking. Here the transactions are executed without any restrictions. It is mainly used when there is low contention for data and it checks for conflicts before the commit.
Asked In: Many Interviews |