37
38 import java.util.function.IntBinaryOperator;
39 import java.util.function.IntUnaryOperator;
40
41 /**
42 * An {@code int} value that may be updated atomically. See the
43 * {@link java.util.concurrent.atomic} package specification for
44 * description of the properties of atomic variables. An
45 * {@code AtomicInteger} is used in applications such as atomically
46 * incremented counters, and cannot be used as a replacement for an
47 * {@link java.lang.Integer}. However, this class does extend
48 * {@code Number} to allow uniform access by tools and utilities that
49 * deal with numerically-based classes.
50 *
51 * @since 1.5
52 * @author Doug Lea
53 */
54 public class AtomicInteger extends Number implements java.io.Serializable {
55 private static final long serialVersionUID = 6214790243416807050L;
56
57 private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
58 private static final long VALUE;
59
60 static {
61 try {
62 VALUE = U.objectFieldOffset
63 (AtomicInteger.class.getDeclaredField("value"));
64 } catch (ReflectiveOperationException e) {
65 throw new Error(e);
66 }
67 }
68
69 private volatile int value;
70
71 /**
72 * Creates a new AtomicInteger with the given initial value.
73 *
74 * @param initialValue the initial value
75 */
76 public AtomicInteger(int initialValue) {
77 value = initialValue;
|
37
38 import java.util.function.IntBinaryOperator;
39 import java.util.function.IntUnaryOperator;
40
41 /**
42 * An {@code int} value that may be updated atomically. See the
43 * {@link java.util.concurrent.atomic} package specification for
44 * description of the properties of atomic variables. An
45 * {@code AtomicInteger} is used in applications such as atomically
46 * incremented counters, and cannot be used as a replacement for an
47 * {@link java.lang.Integer}. However, this class does extend
48 * {@code Number} to allow uniform access by tools and utilities that
49 * deal with numerically-based classes.
50 *
51 * @since 1.5
52 * @author Doug Lea
53 */
54 public class AtomicInteger extends Number implements java.io.Serializable {
55 private static final long serialVersionUID = 6214790243416807050L;
56
57 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
58 private static final long VALUE;
59
60 static {
61 try {
62 VALUE = U.objectFieldOffset
63 (AtomicInteger.class.getDeclaredField("value"));
64 } catch (ReflectiveOperationException e) {
65 throw new Error(e);
66 }
67 }
68
69 private volatile int value;
70
71 /**
72 * Creates a new AtomicInteger with the given initial value.
73 *
74 * @param initialValue the initial value
75 */
76 public AtomicInteger(int initialValue) {
77 value = initialValue;
|