dcsimg
Locking mechanisms
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   kp_k
Posted On:   Tuesday, November 4, 2003 01:53 AM

Hi, Can of any you tell me in simple terms the difference between optimistic locking and pessimistic locking Thanks in advance

Re: Locking mechanisms

Posted By:   Anin_Mathen  
Posted On:   Friday, January 2, 2004 11:43 AM

http://www.javaworld.com/javaworld/jw-07-2001/jw-0713-optimism.html


Try this tutorial..

Anin

Re: Locking mechanisms

Posted By:   Nick_Maiorano  
Posted On:   Tuesday, November 4, 2003 05:33 PM

Kp,



Let's start with pessimistic locking - the simpler of the 2.
Pessimistic locking is an easy way to ensure that nobody else touches your row while you are accessing it. Quite simply, other people will block until you are finished. The problem with this type of locking is that it is very restrictive because it blocks all others trying to access a locked row. Plus, locks are expensive. Overall, this reduces the performance of an application.



Optimistic locking is based on a premise that most of the time, nobody else needs to access your row so why use expensive database locks it in the first place? Optimistic locking never locks any rows but instead is able to detect instances where 2 people modified the same row at the same time (by use of time stamps on the data). In rare cases where this happens, optimistic locking algorithms can choose to abort the transaction and start all over. Since this happens rarely, there is an overall gain in performance.

About | Sitemap | Contact