File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes optimistic and pessimistic concurrency control? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "optimistic and pessimistic concurrency control?" Watch "optimistic and pessimistic concurrency control?" New topic
Author

optimistic and pessimistic concurrency control?

Aaron Raja
Ranch Hand

Joined: Jun 07, 2007
Posts: 206
Difference between optimistic and pessimistic concurrency control? can you tell me at what kind of senerio we use this ?


Thanks, AR
SCWCD 5, SCJP 1.4, OCA (PL/SQL)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Optimistic concurrency control (or optimistic locking) is a technique used with relational databases whereby you use versioning to avoid lost updates. It works by adding some sort of version field to an entity. When your application selects a record from that table it notes the version, when you try to update the record you check the version to see if it is the same. If it isn't, you know that some other process has updated the record and the copy your application has is out of dat, so no update should take place. It is used so as to not require exclusive row locking everytime your application selects a record it them may update, and its called "optimistic" because it works on the assumption that most of the time there will be no conflicts.

Pessimistic concurrency control (or pessimistic locking) is where a row is exclusively locked for the entire duration it is in applciation memory. It is to be avoided, unless you have a good reason to need it, because becomes a bottleneck where more and more users are stuck waiting for locks to be released.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Aaron Raja
Ranch Hand

Joined: Jun 07, 2007
Posts: 206
Thanks Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: optimistic and pessimistic concurrency control?