AtomicInteger,AtomicLong等,这里用volatile修饰的成员变量value,为啥后面又要在静态代码块里面,去通过反射获取转换一下,没看懂。
private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final long valueOffset;
private volatile int value;
static{
try{
valueOffset = unsafe.objectFieldOffset(AtomicInteger.class.getDeclaredField("value"));
}catch(Exception ex){
throw new Error(ex);
}
}