< prev index next >

src/java.base/share/classes/java/util/concurrent/atomic/AtomicBoolean.java

Print this page
8197531: Miscellaneous changes imported from jsr166 CVS 2018-04
Reviewed-by: martin, psandoz


  39 import java.lang.invoke.VarHandle;
  40 
  41 /**
  42  * A {@code boolean} value that may be updated atomically. See the
  43  * {@link VarHandle} specification for descriptions of the properties
  44  * of atomic accesses. An {@code AtomicBoolean} is used in
  45  * applications such as atomically updated flags, and cannot be used
  46  * as a replacement for a {@link java.lang.Boolean}.
  47  *
  48  * @since 1.5
  49  * @author Doug Lea
  50  */
  51 public class AtomicBoolean implements java.io.Serializable {
  52     private static final long serialVersionUID = 4654671469794556979L;
  53     private static final VarHandle VALUE;
  54     static {
  55         try {
  56             MethodHandles.Lookup l = MethodHandles.lookup();
  57             VALUE = l.findVarHandle(AtomicBoolean.class, "value", int.class);
  58         } catch (ReflectiveOperationException e) {
  59             throw new Error(e);
  60         }
  61     }
  62 
  63     private volatile int value;
  64 
  65     /**
  66      * Creates a new {@code AtomicBoolean} with the given initial value.
  67      *
  68      * @param initialValue the initial value
  69      */
  70     public AtomicBoolean(boolean initialValue) {
  71         value = initialValue ? 1 : 0;
  72     }
  73 
  74     /**
  75      * Creates a new {@code AtomicBoolean} with initial value {@code false}.
  76      */
  77     public AtomicBoolean() {
  78     }
  79 




  39 import java.lang.invoke.VarHandle;
  40 
  41 /**
  42  * A {@code boolean} value that may be updated atomically. See the
  43  * {@link VarHandle} specification for descriptions of the properties
  44  * of atomic accesses. An {@code AtomicBoolean} is used in
  45  * applications such as atomically updated flags, and cannot be used
  46  * as a replacement for a {@link java.lang.Boolean}.
  47  *
  48  * @since 1.5
  49  * @author Doug Lea
  50  */
  51 public class AtomicBoolean implements java.io.Serializable {
  52     private static final long serialVersionUID = 4654671469794556979L;
  53     private static final VarHandle VALUE;
  54     static {
  55         try {
  56             MethodHandles.Lookup l = MethodHandles.lookup();
  57             VALUE = l.findVarHandle(AtomicBoolean.class, "value", int.class);
  58         } catch (ReflectiveOperationException e) {
  59             throw new ExceptionInInitializerError(e);
  60         }
  61     }
  62 
  63     private volatile int value;
  64 
  65     /**
  66      * Creates a new {@code AtomicBoolean} with the given initial value.
  67      *
  68      * @param initialValue the initial value
  69      */
  70     public AtomicBoolean(boolean initialValue) {
  71         value = initialValue ? 1 : 0;
  72     }
  73 
  74     /**
  75      * Creates a new {@code AtomicBoolean} with initial value {@code false}.
  76      */
  77     public AtomicBoolean() {
  78     }
  79 


< prev index next >