Deadlock in Databases
Here's why you need to avoid database deadlock.
Join the DZone community and get the full member experience.
Join For FreeFrom databases perspective, a deadlock is a phenomenon that occurs when two transactions are blocking each other.
In the figure above, we have a classic deadlock situation. Transaction A (old man transaction) holds a lock to resource A (Dogs), but it doesn't release it until it will acquire a lock to resource B (Cats) that is currently locked by transaction B (young man transaction). In the same time, transaction B (young man transaction) holds a lock to resource B (Cats), but it doesn't release it until it will acquire a lock to resource A (Dogs) that is currently locked by transaction A (old man transaction).
The application (data access layer) is responsible for managing the acquisition of the lock/release in order to avoid deadlocks, and implicitly performance issues. Without application support, you need to rely on the database capability of detecting and solving deadlocks (commonly, by aborting one of the transactions involved in a deadlock).
You may also like Java Persistence Performance Illustrated Guide.
Opinions expressed by DZone contributors are their own.
Comments