zoukankan      html  css  js  c++  java
  • java中给某个字段加锁

    private String buildLock(String str) {
            StringBuilder sb = new StringBuilder(str);
            String lock = sb.toString().intern();
            return lock;
        }
    
    
    public ResultBean saveYhyhq(String yhqbh, String khh) {
            ResultBean res = new ResultBean();
            try {
                // 加锁
                String lock = buildLock(yhqbh);
                synchronized (lock) {
                    // 查询优惠卷是否可用
                    String yhqxxsql = "select * from tyhqxx where zt = " + GlobalStatusType.YHQZT_QY
                            + " and sxsl > 0 and yhqbh = '" + yhqbh + "'";
                    Tyhqxx tyhqxx = sqlMapper.selectOne(yhqxxsql, Tyhqxx.class);
                    if (tyhqxx == null) {
                        res.setSuccess(false);
                        res.setMessage("来晚了");
                        return res;
                    }
                  
            } catch (Exception e) {
                res.setSuccess(false);
                res.setMessage("异常:" + e.getMessage());
                throw new RuntimeException(e);
            }
            return res;
        }
  • 相关阅读:
    Python(多进程multiprocessing模块)
    Python(队列)
    Unique Paths
    Unique Paths
    Jump Game II
    Jump Game
    Path Sum II
    Path Sum
    Remove Element
    Implement strStr()
  • 原文地址:https://www.cnblogs.com/xianz666/p/13083144.html
Copyright © 2011-2022 走看看