- Optimistic Offline Lock
- Pessimistic Offline Lock
- Coarse-Grained Lock
- Implicit Lock
具体的代码如下:
Optimistic Offline Lock:
最常用的方法:associate a version number with each record in your system:版本号
额外的信息:最后修改时间、修改人
In addition to a version number for each record, storing information as to who last modified a record and when can be quite useful when managing concurrency conflicts.
注意:使用系统时间是不好的做法,因为系统时间不可靠、特别是用于多个系统之间
乐观锁的使用列子:
There's one system using Optimistic Offline Locks that we all should be familiar with: source code management (SCM).
乐观锁的适用场景:
Optimistic concurrency management is appropriate when the chance of conflict between any two business transactions is low.