高并发下的乐观锁

1.本人在项目中经常用到的代码块为:

<update id="updateConsumeStarWithLook">
        update sys_user_consume_star 
            set current_consume_star_amount = current_consume_star_amount +  #{currentConsumeStarAmount, jdbcType=VARCHAR},
                update_time = #{updateTime, jdbcType=TIMESTAMP},
            where id = #{id} 
    </update>

2、在具体调用上述方法的方法上如果需要加上事务,则需要将事务的隔离级别定义为读已提交,不然在查询的时候会出现脏读,更新无法成功,导致死循环

@Transactional(rollbackFor = Exception.class,isolation=Isolation.READ_COMMITTED,propagation=Propagation.REQUIRED)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章