Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Deadlock in Databases

DZone 's Guide to

Deadlock in Databases

Here's why you need to avoid database deadlock.

· Database Zone ·
Free Resource

From databases perspective, a deadlock is a phenomenon that occurs when two transactions are blocking each other.

Image title

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.

Topics:
jpa ,hibernate ,deadlock ,persistence ,database ,performance

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}