设置了不安全变量的位置

时间:2018-01-10 13:30:49

标签: java unsafe atomicboolean

在研究jdk源代码(jdk 1.8.0_111)时,我发现了一段奇怪的代码如下:

public class AtmicBoolean implements Serializable {

    private static final long serialVersionUID = 4654671469794556979L;
    private static final Unsafe unsafe = ;
    private static final long valueOffset;
    private volatile int value;

    static {
        try {
            valueOffset = unsafe.objectFieldOffset(AtomicBoolean.class.getDeclaredField("value"));
        } catch (Exception localException) {
            throw new Error(localException);
        }
    }
  // .... other codes
}

问题: unsafe 变量在哪里设置?

0 个答案:

没有答案