I understand the differences between optimistic and pessimistic locking. Now could someone explain to me when I would use either one in general?
And does the answer
Lot of good things have been said above about optimistic and pessimistic locking. One important point to consider is as follows:
When using optimistic locking, we need to cautious of the fact that how will application recover from these failures.
Specially in asynchronous message driven architectures, this can lead of out of order message processing or lost updates.
Failures scenarios need to be thought through.