zoukankan      html  css  js  c++  java
  • AtomicInteger

    原子量和普通变量相比,主要体现在读写的线程安全上。对原子量的写是原子的,由CAS操作保证原子性。对原子量的读可以读到最新值,由volatile关键字来保证可见性

    ublic class AtomicInteger extends Number implements java.io.Serializable {
        private static final long serialVersionUID = 6214790243416807050L;

        // setup to use Unsafe.compareAndSwapInt for updates
        private static final Unsafe unsafe = Unsafe.getUnsafe();
        private static final long valueOffset;

        static {
          try {
            valueOffset = unsafe.objectFieldOffset
                (AtomicInteger.class.getDeclaredField("value"));
          } catch (Exception ex) { throw new Error(ex); }
        }

        private volatile int value;

    AtomicStampedReference AtomicMarkableReference

    1.为了避免CAS过程中的ABA问题,并发包提供了两个类,AtomicStampedReference和AtomicMarkableReference。前者相当于一个[引用,integer]的二元组,后者相当于一个[引用,boolean]的二元组。

  • 相关阅读:
    23种设计模式之外观模式
    HashMap系列之底层数据结构
    HashMap系列之基本概念
    轻松搞定荷兰国旗问题
    服务治理:Spring Cloud Eureka
    Spring Cloud简介
    简单了解什么是微服务架构
    字符串和时间
    调用shell命令
    s3操作
  • 原文地址:https://www.cnblogs.com/lelouchKOP/p/5792588.html
Copyright © 2011-2022 走看看