并发秒杀,造成的商品超售问题(库存变成负数):
1:开始事务
2:select * from xxxx where id=? for update //行锁
3:update xxxx set sku=sku-1 where id=?
4:事务提交
对某个商品行锁,然后执行库存修改.事务提交后,自动行锁解除,库存正确
并发秒杀,造成的商品超售问题(库存变成负数):
1:开始事务
2:select * from xxxx where id=? for update //行锁
3:update xxxx set sku=sku-1 where id=?
4:事务提交
对某个商品行锁,然后执行库存修改.事务提交后,自动行锁解除,库存正确