• 防止缓存击穿


    public Long querySumJe() {
            String sJe = redisDao.getValue("sumje");
            if(!"null".equalsIgnoreCase(sJe) && sJe != null){
                System.out.println("==========cache");
                return Long.parseLong(sJe);
            }else{
                synchronized (this) {
                    sJe = redisDao.getValue("sumje");
                    if(!"null".equalsIgnoreCase(sJe) && sJe != null){
                        System.out.println("==========cache2");
                        return Long.parseLong(sJe);
                    }
                    System.out.println("==========db");
                    Long je = chjlmxbMapper.querySumJe();
                    redisDao.putValue("sumje", je+"");
                    return je;
                }
            }
        }

    注意:一般的在锁里面不会再查询缓存了,这样就一样会造成缓存击穿,所以在锁中查询数据库前再查询一次缓存是必要的,需要注意。

  • 相关阅读:
    ubuntu使用iso作为本地源
    ubuntu配置简单的DNS服务器
    core data
    Core Animation教程
    制作framework&静态库
    notes
    textkit
    coretext
    nsset
    iOS Development Sites
  • 原文地址:https://www.cnblogs.com/aegisada/p/7521935.html
Copyright © 2020-2023  润新知