16.3.1-sp_getapplock

USE TestSystem
BEGIN TRANSACTION test1
    EXEC  [sp_getapplock] 'AppSourceName' , 'Exclusive'
    WAITFOR DELAY '00:00:5'
    PRINT 'done appLock 1'
COMMIT TRANSACTION test1
USE TestSystem
BEGIN TRANSACTION test2 
    EXEC  [sp_getapplock] 'AppSourceName' , 'Exclusive'
    PRINT 'done second!'
COMMIT TRANSACTION test2 

四个point

1. use TestSystem,必须是同数据库

2. AppSourceName,同资源名称

3. Exclusive,锁定模式相同

4. Begin transaction 必须在事务里面(事务提交/回滚的时候,会自动释放锁)

posted @ 2016-03-01 17:08  脸谱匠  阅读(437)  评论(0编辑  收藏  举报