目录 分布式锁解决方案_数据库乐观锁实现的分布式锁 什么是乐观锁 总是假设最好的情况,每次去拿数据的时候都认为别人不会修改, 所以不会上锁,但是在更新的时候会判断一下在此期间别人有没有 去更新这个数据,可以使用版本号机制和CAS算法实现。 编写乐观锁更新语句 <update id="decreaseStockForVersion" parameterType="int" > UPDATE product SET count = count - # {count}, version = version + 1 WHERE id = #{id} AND count > 0 AND version = #{version} </update> 编写创建订单业务层 /** * 创建订单 乐观锁 * * @return */ @Transactional(rollbackFor = Exception.class) @Override public String createOrder(Integer productId, Integer count) throws Exception {...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with order.setOrder
Contact order.setOrder, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack