put-If-Absent

来源:互联网 发布:神话电话软件 编辑:程序博客网 时间:2024/06/06 05:42

原文引自 : http://wxl24life.iteye.com/blog/1746794

注意:此方法是原子性操作

  1. 如果需要存值,直接调用方法即可;
  2. 如果需要返回同一对象时,需要对返回值进行判断:
Locale l = cache.putIfAbsent(key, locale);    if (l != null) {        locale = l;    }
原创粉丝点击