Chapter 22
Optimistic and Pessimistic locks
Ultra popular question.
Basically, the question is always somewhere around: "You have 2 users updating one account simultaneously. How do you make this operation safe?"
Here you should know that one of the ways is to lock the operation. There are 2 types of locks.
Optimistic Locks 🙂
It is a strategy: assume conflicts are rare, don't lock anything up front, and check at commit time whether someone else changed the data.
Rule of thumb: We have more reads than writes. When a new transaction comes in, we are optimistic that the data has not changed — because there are not many writes happening.
Part of the full course
Unlock this chapter
This one is part of the paid course. Everything before the interview, the free sampler articles, the Core Java drills, and mock interviews stay open either way.