1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * This file is available under and governed by the GNU General Public
  27  * License version 2 only, as published by the Free Software Foundation.
  28  * However, the following notice accompanied the original version of this
  29  * file:
  30  *
  31  * Written by Doug Lea with assistance from members of JCP JSR-166
  32  * Expert Group and released to the public domain, as explained at
  33  * http://creativecommons.org/publicdomain/zero/1.0/
  34  */
  35 
  36 /**
  37  * A small toolkit of classes that support lock-free thread-safe
  38  * programming on single variables.  Instances of Atomic classes
  39  * maintain values that are accessed and updated using methods
  40  * otherwise available for fields using associated atomic {@link
  41  * java.lang.invoke.VarHandle} operations.
  42  *
  43  * <p>Instances of classes
  44  * {@link java.util.concurrent.atomic.AtomicBoolean},
  45  * {@link java.util.concurrent.atomic.AtomicInteger},
  46  * {@link java.util.concurrent.atomic.AtomicLong}, and
  47  * {@link java.util.concurrent.atomic.AtomicReference}
  48  * each provide access and updates to a single variable of the
  49  * corresponding type.  Each class also provides appropriate utility
  50  * methods for that type.  For example, classes {@code AtomicLong} and
  51  * {@code AtomicInteger} provide atomic increment methods.  One
  52  * application is to generate sequence numbers, as in:
  53  *
  54  * <pre> {@code
  55  * class Sequencer {
  56  *   private final AtomicLong sequenceNumber
  57  *     = new AtomicLong(0);
  58  *   public long next() {
  59  *     return sequenceNumber.getAndIncrement();
  60  *   }
  61  * }}</pre>
  62  *
  63  * <p>Arbitrary transformations of the contained value are provided both
  64  * by low-level read-modify-write operations such as {@code compareAndSet}
  65  * and by higher-level methods such as {@code getAndUpdate}.
  66  *
  67  * <p>These classes are not general purpose replacements for {@code
  68  * java.lang.Integer} and related classes.  They do <em>not</em>
  69  * define methods such as {@code equals}, {@code hashCode} and {@code
  70  * compareTo}.  Because atomic variables are expected to be mutated,
  71  * they are poor choices for hash table keys.
  72  *
  73  * <p>The
  74  * {@link java.util.concurrent.atomic.AtomicIntegerArray},
  75  * {@link java.util.concurrent.atomic.AtomicLongArray}, and
  76  * {@link java.util.concurrent.atomic.AtomicReferenceArray} classes
  77  * further extend atomic operation support to arrays of these types.
  78  * These classes are also notable in providing {@code volatile} access
  79  * semantics for their array elements.
  80  *
  81  * <p>In addition to classes representing single values and arrays,
  82  * this package contains <em>Updater</em> classes that can be used to
  83  * obtain {@code compareAndSet} and related operations on any selected
  84  * {@code volatile} field of any selected class. These classes
  85  * predate the introduction of {@link
  86  * java.lang.invoke.VarHandle}, and are of more limited use.
  87  * {@link java.util.concurrent.atomic.AtomicReferenceFieldUpdater},
  88  * {@link java.util.concurrent.atomic.AtomicIntegerFieldUpdater}, and
  89  * {@link java.util.concurrent.atomic.AtomicLongFieldUpdater} are
  90  * reflection-based utilities that provide access to the associated
  91  * field types.  These are mainly of use in atomic data structures in
  92  * which several {@code volatile} fields of the same node (for
  93  * example, the links of a tree node) are independently subject to
  94  * atomic updates.  These classes enable greater flexibility in how
  95  * and when to use atomic updates, at the expense of more awkward
  96  * reflection-based setup, less convenient usage, and weaker
  97  * guarantees.
  98  *
  99  * <p>The {@link java.util.concurrent.atomic.AtomicMarkableReference}
 100  * class associates a single boolean with a reference.  For example, this
 101  * bit might be used inside a data structure to mean that the object
 102  * being referenced has logically been deleted.
 103  *
 104  * The {@link java.util.concurrent.atomic.AtomicStampedReference}
 105  * class associates an integer value with a reference.  This may be
 106  * used for example, to represent version numbers corresponding to
 107  * series of updates.
 108  *
 109  * @since 1.5
 110  */
 111 package java.util.concurrent.atomic;