jubincn

导航

2013年7月23日 #

Compare and Swap(CAS)

摘要: CAS(Compare and Swap)是个原子操作。拿到一个新值后,CAS将其与内存中的值进行比较,若内存中的值和这个值不一样,则将这个值写入内存,否则,不做操作。在Java的java.util.concurrent.atomic包中对CAS的实现是通过synchronized关键字实现的: public final synchronized boolean compareAndSet(long expect, long update) { if (value == expect) { ... 阅读全文

posted @ 2013-07-23 18:24 jubincn 阅读(239) 评论(0) 推荐(0)

Java中自动装箱代码初探

摘要: 《深入理解Java虚拟机》中讲语法糖时,提到了下面这个例子(不是原文中的例子,我自己改过):public class AutoBoxingTest { /** * @param args */ public static void main(String[] args) { Integer a = 1; Integer b = 2; Integer c = 127; Integer d = 127; Integer e = 3; Integer f = 3; Long g = 3L; System.out.println(c == d); S... 阅读全文

posted @ 2013-07-23 14:40 jubincn 阅读(169) 评论(0) 推荐(0)