
what is difference between optimistic and pessimistic locking

Pessimistic locking is where a record or page is locked immediately when the lock is requested.While Optimistic locking is where a record or page is only locked when the changes made to that record are updated.
The Optimistic locking situation is only appropriate 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.