aba的问题使用AtomicStampedReference
使用版本号来解决,其实用的还是cas,静态内部类中封装了stamp
private static class Pair<T> {
final T reference;
final int stamp;
private Pair(T reference, int stamp) {
this.reference = reference;
this.stamp = stamp;
}
static <T> Pair<T> of(T reference, int stamp) {
return new Pair<T>(reference, stamp);
}
}