Chapter 8. Handling concurrency and transactions
This chapter covers
- Understanding the concurrency problem
- Configuring concurrency
- Managing concurrency exceptions
- Managing transactions
Suppose you want to book a flight online. You search for the flight you want and find an available seat, but when you click the reservation button, the system says the flight is fully booked. If you search for the flight again, it isn’t shown.
What happened is that at the moment when you searched for the flight, a seat was available; but in the time between the search response and the booking attempt, someone else booked the last seat. There were concurrent searches for the last seat, and the first person to book it won. If the booking application hadn’t checked for concurrency, the flight would have been overbooked.
When you book a flight, you register on the carrier’s website, and your information is stored so it can be retrieved and updated anytime you want. This kind of data is rarely updated and is only modified by you or a carrier’s employee. Contention in this context is so low that you can easily live without concurrency checks.