zoukankan      html  css  js  c++  java
  • 记一次数据库事务锁

    最近在做项目的时候碰到一个问题,事务锁。

    TransactionOptions tos = new TransactionOptions();

    tos.IsolationLevel = IsolationLevel.RepeatableRead; //行锁 只会锁住当前操作的那一行数据,当前表的其他数据不受影响。 (已验证)

    //IsolationLevel.Serializable;  //表锁 当前操作会将整张表锁住,只有该事务提交后,才可以操作该表的数据 (已验证)

    //"select * from tableName where id = 1 for update"; //查询的时候使用 for update,当前数据行仍然可以更新,只是在该事物还未提交时,其他事务再操作这张表就会锁行,需要等待该事务提交完毕才可以操作和提交(未验证)

    tos.Timeout = new TimeSpan(0, 2, 0);

    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, tos))
    {
     
      //业务处理
      InitStockQty(item);
      ts.Complete();
    }

  • 相关阅读:
    centos git编译
    Unix/Linux小计
    centos gcc编译
    c++隐式转换(implicit conversion)
    通用c程序Makefile
    对弈的Python学习笔记
    LeetCode最长回文子串
    JDBC09 CLOB文本大对象
    JDBC08时间处理
    JDBC07 事务
  • 原文地址:https://www.cnblogs.com/opts/p/9138511.html
Copyright © 2011-2022 走看看