AtomicInteger如何保证线程安全?

1. AtomicInteger不是final类型,如何保证线程安全?

public class AtomicInteger extends Number implements java.io.Serializable {

private static final long serialVersionUID = 6214790243416807050L;

/*

* This class intended to be implemented using VarHandles, but there

* are unresolved cyclic startup dependencies.

*/

private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();

private static final long VALUE = U.objectFieldOffset(AtomicInteger.class, "value");

private volatile int value;

/**

* Creates a new AtomicInteger with the given initial value.

*

* @param initialValue the initial value

*/

public AtomicInteger(int initialValue) {

value = initialValue;

}

/**

* Creates a new AtomicInteger with initial value {@code 0}.

*/

public AtomicInteger() {

你可能感兴趣的:(java,开发语言)