jdk/src/share/classes/java/util/concurrent/atomic/package-info.java
author chegar
Thu, 10 Jan 2013 21:52:38 +0000
changeset 15020 50394fa17c1b
parent 14325 622c473a21aa
child 18576 7a5c231327af
permissions -rw-r--r--
8006007: j.u.c.atomic classes should use intrinsic getAndXXX provided by 7023898 Reviewed-by: dl, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Written by Doug Lea with assistance from members of JCP JSR-166
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Expert Group and released to the public domain, as explained at
9242
ef138d47df58 7034657: Update Creative Commons license URL in legal notices
dl
parents: 5506
diff changeset
    33
 * http://creativecommons.org/publicdomain/zero/1.0/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A small toolkit of classes that support lock-free thread-safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * programming on single variables.  In essence, the classes in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * package extend the notion of {@code volatile} values, fields, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * array elements to those that also provide an atomic conditional update
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * operation of the form:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    43
 *  <pre> {@code boolean compareAndSet(expectedValue, updateValue);}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>This method (which varies in argument types across different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * classes) atomically sets a variable to the {@code updateValue} if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * currently holds the {@code expectedValue}, reporting {@code true} on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * success.  The classes in this package also contain methods to get and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * unconditionally set values, as well as a weaker conditional atomic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * update operation {@code weakCompareAndSet} described below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>The specifications of these methods enable implementations to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * employ efficient machine-level atomic instructions that are available
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * on contemporary processors.  However on some platforms, support may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * entail some form of internal locking.  Thus the methods are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * strictly guaranteed to be non-blocking --
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * a thread may block transiently before performing the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>Instances of classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * {@link java.util.concurrent.atomic.AtomicBoolean},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * {@link java.util.concurrent.atomic.AtomicInteger},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * {@link java.util.concurrent.atomic.AtomicLong}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * {@link java.util.concurrent.atomic.AtomicReference}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * each provide access and updates to a single variable of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * corresponding type.  Each class also provides appropriate utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * methods for that type.  For example, classes {@code AtomicLong} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * {@code AtomicInteger} provide atomic increment methods.  One
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * application is to generate sequence numbers, as in:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    70
 *  <pre> {@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * class Sequencer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *   private final AtomicLong sequenceNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *     = new AtomicLong(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   public long next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *     return sequenceNumber.getAndIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *   }
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    77
 * }}</pre>
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    78
 *
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    79
 * <p>It is straightforward to define new utility functions that, like
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    80
 * {@code getAndIncrement}, apply a function to a value atomically.
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    81
 * For example, given some transformation
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    82
 * <pre> {@code long transform(long input)}</pre>
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    83
 *
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    84
 * write your utility method as follows:
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    85
 *  <pre> {@code
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    86
 * long getAndTransform(AtomicLong var) {
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    87
 *   while (true) {
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    88
 *     long current = var.get();
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    89
 *     long next = transform(current);
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    90
 *     if (var.compareAndSet(current, next))
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    91
 *         return current;
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    92
 *         // return next; for transformAndGet
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    93
 *   }
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    94
 * }}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <p>The memory effects for accesses and updates of atomics generally
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    97
 * follow the rules for volatiles, as stated in
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    98
 * <a href="http://docs.oracle.com/javase/specs/jls/se7/html/index.html">
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
    99
 * The Java Language Specification, Third Edition (17.4 Memory Model)</a>:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *   <li> {@code get} has the memory effects of reading a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * {@code volatile} variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *   <li> {@code set} has the memory effects of writing (assigning) a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * {@code volatile} variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *   <li> {@code lazySet} has the memory effects of writing (assigning)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *   a {@code volatile} variable except that it permits reorderings with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *   subsequent (but not previous) memory actions that do not themselves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *   impose reordering constraints with ordinary non-{@code volatile}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *   writes.  Among other usage contexts, {@code lazySet} may apply when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *   nulling out, for the sake of garbage collection, a reference that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *   never accessed again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *   <li>{@code weakCompareAndSet} atomically reads and conditionally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *   writes a variable but does <em>not</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *   create any happens-before orderings, so provides no guarantees
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *   with respect to previous or subsequent reads and writes of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *   variables other than the target of the {@code weakCompareAndSet}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *   <li> {@code compareAndSet}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *   and all other read-and-update operations such as {@code getAndIncrement}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *   have the memory effects of both reading and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *   writing {@code volatile} variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * <p>In addition to classes representing single values, this package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * contains <em>Updater</em> classes that can be used to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * {@code compareAndSet} operations on any selected {@code volatile}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * field of any selected class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * {@link java.util.concurrent.atomic.AtomicReferenceFieldUpdater},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * {@link java.util.concurrent.atomic.AtomicIntegerFieldUpdater}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * {@link java.util.concurrent.atomic.AtomicLongFieldUpdater} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * reflection-based utilities that provide access to the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * field types.  These are mainly of use in atomic data structures in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * which several {@code volatile} fields of the same node (for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * example, the links of a tree node) are independently subject to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * atomic updates.  These classes enable greater flexibility in how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * and when to use atomic updates, at the expense of more awkward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * reflection-based setup, less convenient usage, and weaker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * guarantees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <p>The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * {@link java.util.concurrent.atomic.AtomicIntegerArray},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * {@link java.util.concurrent.atomic.AtomicLongArray}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * {@link java.util.concurrent.atomic.AtomicReferenceArray} classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * further extend atomic operation support to arrays of these types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * These classes are also notable in providing {@code volatile} access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * semantics for their array elements, which is not supported for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * ordinary arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * <a name="Spurious">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * <p>The atomic classes also support method {@code weakCompareAndSet},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * which has limited applicability.  On some platforms, the weak version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * may be more efficient than {@code compareAndSet} in the normal case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * but differs in that any given invocation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * {@code weakCompareAndSet} method may return {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <em>spuriously</em> (that is, for no apparent reason)</a>.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * {@code false} return means only that the operation may be retried if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * desired, relying on the guarantee that repeated invocation when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * variable holds {@code expectedValue} and no other thread is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * attempting to set the variable will eventually succeed.  (Such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * spurious failures may for example be due to memory contention effects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * that are unrelated to whether the expected and current values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * equal.)  Additionally {@code weakCompareAndSet} does not provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * ordering guarantees that are usually needed for synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * control.  However, the method may be useful for updating counters and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * statistics when such updates are unrelated to the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * happens-before orderings of a program.  When a thread sees an update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * to an atomic variable caused by a {@code weakCompareAndSet}, it does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * not necessarily see updates to any <em>other</em> variables that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * occurred before the {@code weakCompareAndSet}.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * acceptable when, for example, updating performance statistics, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * rarely otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * <p>The {@link java.util.concurrent.atomic.AtomicMarkableReference}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * class associates a single boolean with a reference.  For example, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * bit might be used inside a data structure to mean that the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * being referenced has logically been deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * The {@link java.util.concurrent.atomic.AtomicStampedReference}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * class associates an integer value with a reference.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * used for example, to represent version numbers corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * series of updates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * <p>Atomic classes are designed primarily as building blocks for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * implementing non-blocking data structures and related infrastructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * classes.  The {@code compareAndSet} method is not a general
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * replacement for locking.  It applies only when critical updates for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * object are confined to a <em>single</em> variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * <p>Atomic classes are not general purpose replacements for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * {@code java.lang.Integer} and related classes.  They do <em>not</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * define methods such as {@code hashCode} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * {@code compareTo}.  (Because atomic variables are expected to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * mutated, they are poor choices for hash table keys.)  Additionally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * classes are provided only for those types that are commonly useful in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * intended applications.  For example, there is no atomic class for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * representing {@code byte}.  In those infrequent cases where you would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * like to do so, you can use an {@code AtomicInteger} to hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * {@code byte} values, and cast appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * You can also hold floats using
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
   207
 * {@link java.lang.Float#floatToRawIntBits} and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * {@link java.lang.Float#intBitsToFloat} conversions, and doubles using
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
   209
 * {@link java.lang.Double#doubleToRawLongBits} and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * {@link java.lang.Double#longBitsToDouble} conversions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
package java.util.concurrent.atomic;