简体   繁体   中英

How to avoid database deadlocks

I have a clustered application that is suffering from database deadlocks.

It is a j2ee application using JPA and hibernate. The database is DB2 8.1 on Z/OS is set to page locking (this is a requirement for the company).

The problem is that the primary key are generated as a sequence, and will often deadlock while trying to insert records if the system has any significant load.

Are there any "best practices" to reducing the probability of a deadlock?

"Are there any "best practices" to reducing the probability of a deadlock?"

Deadlock means 2 (or more) processes, 2 (or more) resources and two distinct orders for access.

Process 1 has to get A and B.

Process 2 has to get B and be waiting for A.

If every process would get A first, the incidence of deadlock is reduced.

Since you're deadlocking on an entire page, it's hard to assure that everyone gets the same page to start their transaction.

You can try to reduce conflicts by assuring that rows are widely scrambled among the pages.

You can try to reduce conflicts by introducing a "You Must Get This First" row which will effectively single-thread applications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM