开发者

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 开发者_Go百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜