通过数据库也可以实现分布式锁,但是在高并发的情况下,数据库压力较大,所以很少使用。 比如超卖问题:把条件判断放在 sql 中 <update id="decreaseItemCount">update items_specset stock = stock - #{pendingCounts}where id = #{spech}and stock >= #{pendingCounts}</update>