高併發下的樂觀鎖

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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章