当前位置: 代码迷 >> J2SE >> 更新cache,这么写好吗
  详细解决方案

更新cache,这么写好吗

热度:151   发布时间:2016-04-23 20:17:48.0
更新cache,这样写好吗?



private static ConcurrentMap<String, KetamaEntity> cache = new ConcurrentHashMap<String, KetamaEntity>();

public void update(){
ConcurrentMap<String, KetamaEntity> temp = cache;
long start = System.currentTimeMillis();
try {
cache = null;
cache = getCache();//这里获取会比较耗时;
} catch (Exception e) {
log.error("error", e);
}
if (cache == null || cache.size() == 0) {
cache = temp;
}}

------解决思路----------------------
不明觉厉 
  相关解决方案