p.p1 { margin: 0; font: 11px Monaco }
span.s1 { color: rgba(147, 26, 104, 1) }
span.s2 { color: rgba(126, 80, 79, 1) }

CAS是unSafe类中compareAndSwapInt,compareAndSwapLong等几个方法包装提供

public final int incrementAndGet() {

for (;;) {

int current = get();

int next = current + 1;

if (compareAndSet(current, next))

return next;

}

}

p.p1 { margin: 0; font: 11px Monaco }
span.s1 { color: rgba(147, 26, 104, 1) }
span.s2 { color: rgba(126, 80, 79, 1) }
span.s3 { color: rgba(3, 38, 204, 1) }

public final boolean compareAndSet(int expect, int update) {

return unsafe.compareAndSwapInt(this, valueOffset, expect, update);

}

原来对它的原理一直不大理解

通过注释解读反而很清楚了

原来它是通过比较value和上文中的所谓的期望值current进行最终比较  如果相等  认为没被篡改过

但其实还是会有ABA问题

就是

最新文章

  1. mac 终端 常用命令
  2. Yii2 用户登录
  3. Button 设置适应不同版本 旋转以后大小相应的改变
  4. zepto - push
  5. 奇怪的JS正则之 /[A-z]/.test("\\"); // true
  6. UltraEdit 和Notepad++ 使用ftp直接编辑linux上文件
  7. poj 2094 多项式求和。
  8. hdu1114(完全背包)
  9. clientIDMode的应用
  10. win7 Python 环境 准备 配置
  11. 随笔css的样式
  12. (一)php的基本知识和一些注意点
  13. 3Delight NSI: A Streamable Render API
  14. day16
  15. Web 开发技术文档大全
  16. Django框架(三)
  17. linux命令行命令
  18. 用TexturePacker打图集用于UGUI中
  19. datatable表格框架服务器端分页查询设置
  20. 使用java8的StreamAPI对集合计算进行代码重构

热门文章

  1. Python使用import导入模块时报ValueError: source code string cannot contain null bytes的解决方案
  2. 第8章 Python类中常用的特殊变量和方法目录
  3. PyQt(Python+Qt)学习随笔:gridLayout的layoutHorizontalSpacing和layoutVerticalSpacing属性
  4. Java数据结构(十五)—— 多路查找树
  5. 安装nginx并安全地配置和启动
  6. Echarts的食用方式
  7. Python-Wechaty: 面向所有IM软件的聊天机器人框架
  8. 题解-洛谷P7114 字符串匹配
  9. C# 高性能对象映射
  10. sqli-labs lexx25-28a(各种过滤)