Avoid Deadlocks (339)

Multitable deadlocks can usually be avoided if transactions accessing the same tables
lock those tables in the same order, either through implicit or explicit locks. For
example, all application developers might follow the rule that when both a master and
detail table are updated, the master table is locked first and then the detail table. If
such rules are properly designed and then followed in all applications, deadlocks are
very unlikely to occur.

When you know you will require a sequence of locks for one transaction, consider
acquiring the most exclusive (least compatible) lock first.

避免死锁
1. 如果事务按相同的顺序对相同的表加锁(隐式或显式),通常都能避免多表死锁
2. 当预先知道一个事务内需要获取一系列的锁时 , 可以考虑先获取排他性最高的锁

[@more@]
请使用浏览器的分享功能分享到微信等