posted 16 years ago
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.