Loading

悲观锁与乐观锁

1.悲观锁,每次使用的时候加锁 比如入账交易,一上来查询账户的时候就select * from account where accountid = ? for update;

2.乐观锁,不必每次使用的是时候加锁,而是比如在account表里面增加字段version,使用的时候select * from account where acctountid = ? and version=1 for update;

然后在交易结束的时候update account set amt = ? version = 2 where account id = ? and version = 1

posted @ 2017-06-26 15:19  注销111  阅读(116)  评论(0编辑  收藏  举报