39 import java.lang.invoke.VarHandle;
40 import java.util.function.BinaryOperator;
41 import java.util.function.UnaryOperator;
42
43 /**
44 * An object reference that may be updated atomically. See the {@link
45 * VarHandle} specification for descriptions of the properties of
46 * atomic accesses.
47 * @since 1.5
48 * @author Doug Lea
49 * @param <V> The type of object referred to by this reference
50 */
51 public class AtomicReference<V> implements java.io.Serializable {
52 private static final long serialVersionUID = -1848883965231344442L;
53 private static final VarHandle VALUE;
54 static {
55 try {
56 MethodHandles.Lookup l = MethodHandles.lookup();
57 VALUE = l.findVarHandle(AtomicReference.class, "value", Object.class);
58 } catch (ReflectiveOperationException e) {
59 throw new Error(e);
60 }
61 }
62
63 private volatile V value;
64
65 /**
66 * Creates a new AtomicReference with the given initial value.
67 *
68 * @param initialValue the initial value
69 */
70 public AtomicReference(V initialValue) {
71 value = initialValue;
72 }
73
74 /**
75 * Creates a new AtomicReference with null initial value.
76 */
77 public AtomicReference() {
78 }
79
|
39 import java.lang.invoke.VarHandle;
40 import java.util.function.BinaryOperator;
41 import java.util.function.UnaryOperator;
42
43 /**
44 * An object reference that may be updated atomically. See the {@link
45 * VarHandle} specification for descriptions of the properties of
46 * atomic accesses.
47 * @since 1.5
48 * @author Doug Lea
49 * @param <V> The type of object referred to by this reference
50 */
51 public class AtomicReference<V> implements java.io.Serializable {
52 private static final long serialVersionUID = -1848883965231344442L;
53 private static final VarHandle VALUE;
54 static {
55 try {
56 MethodHandles.Lookup l = MethodHandles.lookup();
57 VALUE = l.findVarHandle(AtomicReference.class, "value", Object.class);
58 } catch (ReflectiveOperationException e) {
59 throw new ExceptionInInitializerError(e);
60 }
61 }
62
63 private volatile V value;
64
65 /**
66 * Creates a new AtomicReference with the given initial value.
67 *
68 * @param initialValue the initial value
69 */
70 public AtomicReference(V initialValue) {
71 value = initialValue;
72 }
73
74 /**
75 * Creates a new AtomicReference with null initial value.
76 */
77 public AtomicReference() {
78 }
79
|