Google

Tuesday, October 11, 2005

Pessimistic and optimistic locking

Pessimistic and optimistic locking

There are two different ways transactional locking is done.
Pessimistic and optimistic locking and that is how transactional isolation is achieved.

When we do pessimistic locking, we lock the resource when it is accessed the very first time and the lock is not released till the time, transaction is finished i.e, either committed or rolled back. The disadvantages of this apporach will be that the resource will be locked and no other process can access this resource till the lock is released. This can result in lock contention and the other processing trying to access the lock will be either delayed or their transaction will be rolled back.

WIth the optimistic locking, the resouece is not locked the way it is done in the case of pessimistic locking. The time the resource is first accessed, the state of the resource is saved. And when it is the time for the resource to be updated, the current state and the saved state is matched. Is their is any difference, the transaction is rolled back. This way the other transactions are not rolled.

This is the theory, but I am not sure how it works in reality. Sounds to me to be a complex way to achieve transaction isloation and what if this resource in question, is accessed frequently. Will this not result in performance bottleneck?

1 Comments:

Anonymous Anonymous said...

Hey, you have a nice blog here! Awesome job. I have
a cowboy boot site. It pretty much covers cowboy boot related stuff.

Come and check it out when you get time :-)

7:23 AM  

Post a Comment

<< Home