锁的使用

注意要成对,重点是代码中有分支或者异常返回的情况,这种情况要在异常返回前先释放锁

    mysqlInstanceLock.Lock()
    slaveHostSql := "show slave hosts"
    ss1 := dc.SqlRes(DcServer, ip, port, msdb.DbName, slaveHostSql,false , common.AdminMysqlUserName, common.AdminMysqlPassword)
    

    if ss1 == "" {  //has not slave hosts;
        mysqlInstanceLock.Unlock()
        return
    }


    mysqlInstanceLock.Unlock()

 

相关文章:

  • 2022-12-23
  • 2021-10-24
  • 2021-06-13
  • 2021-11-03
  • 2021-06-23
  • 2022-02-11
  • 2022-03-02
猜你喜欢
  • 2021-09-14
  • 2021-06-13
  • 2021-10-13
  • 2021-05-26
  • 2021-11-10
  • 2021-09-16
相关资源
相似解决方案