Java-Interview-Advanced/docs/distributed-system/distributed-lock.md

12 lines
563 B
Markdown
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

下订单的环节,支付之前,创建一个订单
![distributed-lock](/docs/distributed-system/images/distributed-lock.png)
创建一个订单,订单里会指定对哪些商品要购买多少件,此时就需要走一个流程,校验一下库存
查库存,确认库存充足,锁定库存
这个过程必须用分布式锁,锁掉这个商品的库存,对一个商品的购买同一时间只能有一个人操作
redis和zookeeper实现分布式锁的原理在之前面试突击第一季都讲过了大家没看过的可以去看一下