解惑关于多台服务器并发问题涉及到数据库锁的问题

来源:互联网 发布:linux网络编程书籍 编辑:程序博客网 时间:2024/05/16 06:38

1.关于并发情况事物的控制,一般通过spring框架来指定到service方法来保证方法内多次数据库的事物一致性。

        eg 关于spring中tx标签对事物的控制配置属性如下

        <tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="list*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />  //该方法来保证事物一致性
</tx:attributes>
</tx:advice>


2.多台服务器并发情况下访问该方法时,可能数据出现问题。

     可用过乐观锁的方式 加上一个字段status,因为update默认加锁

     通过悲观锁,select * from table where id=‘’ for update

                             或者  select * from table where id=‘’ for nowwaite()




0 0
原创粉丝点击