jdk/src/share/classes/java/util/concurrent/package-info.java
author jjh
Wed, 13 Apr 2011 12:16:13 -0700
changeset 9266 121fb370f179
parent 9242 ef138d47df58
child 14325 622c473a21aa
permissions -rw-r--r--
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks 7032965: API files in java.io need to updated for references to JVM Spec with editions/hyperlinks 7032958: API files in java.lang need to updated for references to JLS with editions/hyperlinks 7032961: API files in java.lang need to updated for references to JVM with editions/hyperlinks 7032976: API files in javax.lang need to be updated for references to JLS with editions/hyperlinks 7032959: API files in java.util need to updated for references to JLS with editions/hyperlinks 7032962: API files in java.util need to updated for references to JVM Spec with editions/hyperlinks 7032967: API files in java.security need to updated for references to JVM Spec with editions/hyperlinks 7032955: API files in java.math need to updated for references to JLS with editions/hyperlinks Summary: Removed URLs and 'edition' references Reviewed-by: darcy
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: 4110
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: 4110
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: 4110
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4110
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4110
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
 * Utility classes commonly useful in concurrent programming.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * package includes a few small standardized extensible frameworks, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * well as some classes that provide useful functionality and are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * otherwise tedious or difficult to implement.  Here are brief
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * descriptions of the main components.  See also the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * {@link java.util.concurrent.locks} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * {@link java.util.concurrent.atomic} packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <h2>Executors</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <b>Interfaces.</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * {@link java.util.concurrent.Executor} is a simple standardized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * interface for defining custom thread-like subsystems, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * thread pools, asynchronous IO, and lightweight task frameworks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Depending on which concrete Executor class is being used, tasks may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * execute in a newly created thread, an existing task-execution thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * or the thread calling {@link java.util.concurrent.Executor#execute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * execute}, and may execute sequentially or concurrently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * {@link java.util.concurrent.ExecutorService} provides a more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * complete asynchronous task execution framework.  An
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * ExecutorService manages queuing and scheduling of tasks,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * and allows controlled shutdown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * The {@link java.util.concurrent.ScheduledExecutorService}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * subinterface and associated interfaces add support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * delayed and periodic task execution.  ExecutorServices
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * provide methods arranging asynchronous execution of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * function expressed as {@link java.util.concurrent.Callable},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * the result-bearing analog of {@link java.lang.Runnable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * A {@link java.util.concurrent.Future} returns the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * a function, allows determination of whether execution has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * completed, and provides a means to cancel execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * A {@link java.util.concurrent.RunnableFuture} is a {@code Future}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * that possesses a {@code run} method that upon execution,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * sets its results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <b>Implementations.</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Classes {@link java.util.concurrent.ThreadPoolExecutor} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * {@link java.util.concurrent.ScheduledThreadPoolExecutor}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * provide tunable, flexible thread pools.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * The {@link java.util.concurrent.Executors} class provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * factory methods for the most common kinds and configurations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * of Executors, as well as a few utility methods for using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * them.  Other utilities based on {@code Executors} include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * concrete class {@link java.util.concurrent.FutureTask}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * providing a common extensible implementation of Futures, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * {@link java.util.concurrent.ExecutorCompletionService}, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * assists in coordinating the processing of groups of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * asynchronous tasks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
    95
 * <p>Class {@link java.util.concurrent.ForkJoinPool} provides an
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
    96
 * Executor primarily designed for processing instances of {@link
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
    97
 * java.util.concurrent.ForkJoinTask} and its subclasses.  These
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
    98
 * classes employ a work-stealing scheduler that attains high
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
    99
 * throughput for tasks conforming to restrictions that often hold in
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   100
 * computation-intensive parallel processing.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   101
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <h2>Queues</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * The {@link java.util.concurrent.ConcurrentLinkedQueue} class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * supplies an efficient scalable thread-safe non-blocking FIFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <p>Five implementations in {@code java.util.concurrent} support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * the extended {@link java.util.concurrent.BlockingQueue}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * interface, that defines blocking versions of put and take:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * {@link java.util.concurrent.LinkedBlockingQueue},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * {@link java.util.concurrent.ArrayBlockingQueue},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * {@link java.util.concurrent.SynchronousQueue},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * {@link java.util.concurrent.PriorityBlockingQueue}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * {@link java.util.concurrent.DelayQueue}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * The different classes cover the most common usage contexts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * for producer-consumer, messaging, parallel tasking, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * related concurrent designs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   120
 * <p> Extended interface {@link java.util.concurrent.TransferQueue},
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   121
 * and implementation {@link java.util.concurrent.LinkedTransferQueue}
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   122
 * introduce a synchronous {@code transfer} method (along with related
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   123
 * features) in which a producer may optionally block awaiting its
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   124
 * consumer.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   125
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <p>The {@link java.util.concurrent.BlockingDeque} interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * extends {@code BlockingQueue} to support both FIFO and LIFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * (stack-based) operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * Class {@link java.util.concurrent.LinkedBlockingDeque}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * provides an implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * <h2>Timing</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * The {@link java.util.concurrent.TimeUnit} class provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * multiple granularities (including nanoseconds) for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * specifying and controlling time-out based operations.  Most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * classes in the package contain operations based on time-outs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * in addition to indefinite waits.  In all cases that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * time-outs are used, the time-out specifies the minimum time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * that the method should wait before indicating that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * timed-out.  Implementations make a &quot;best effort&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * to detect time-outs as soon as possible after they occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * However, an indefinite amount of time may elapse between a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * time-out being detected and a thread actually executing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * again after that time-out.  All methods that accept timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * parameters treat values less than or equal to zero to mean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * not to wait at all.  To wait "forever", you can use a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * of {@code Long.MAX_VALUE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <h2>Synchronizers</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   152
 * Five classes aid common special-purpose synchronization idioms.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   153
 * <ul>
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   154
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   155
 * <li>{@link java.util.concurrent.Semaphore} is a classic concurrency tool.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   156
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   157
 * <li>{@link java.util.concurrent.CountDownLatch} is a very simple yet
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   158
 * very common utility for blocking until a given number of signals,
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   159
 * events, or conditions hold.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   160
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   161
 * <li>A {@link java.util.concurrent.CyclicBarrier} is a resettable
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   162
 * multiway synchronization point useful in some styles of parallel
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   163
 * programming.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   164
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   165
 * <li>A {@link java.util.concurrent.Phaser} provides
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   166
 * a more flexible form of barrier that may be used to control phased
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   167
 * computation among multiple threads.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   168
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   169
 * <li>An {@link java.util.concurrent.Exchanger} allows two threads to
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   170
 * exchange objects at a rendezvous point, and is useful in several
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   171
 * pipeline designs.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   172
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   173
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <h2>Concurrent Collections</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * Besides Queues, this package supplies Collection implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * designed for use in multithreaded contexts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * {@link java.util.concurrent.ConcurrentHashMap},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * {@link java.util.concurrent.ConcurrentSkipListMap},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * {@link java.util.concurrent.ConcurrentSkipListSet},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * {@link java.util.concurrent.CopyOnWriteArrayList}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * {@link java.util.concurrent.CopyOnWriteArraySet}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * When many threads are expected to access a given collection, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * {@code ConcurrentHashMap} is normally preferable to a synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * {@code HashMap}, and a {@code ConcurrentSkipListMap} is normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * preferable to a synchronized {@code TreeMap}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * A {@code CopyOnWriteArrayList} is preferable to a synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * {@code ArrayList} when the expected number of reads and traversals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * greatly outnumber the number of updates to a list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * <p>The "Concurrent" prefix used with some classes in this package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * is a shorthand indicating several differences from similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * "synchronized" classes.  For example {@code java.util.Hashtable} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * {@code Collections.synchronizedMap(new HashMap())} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * synchronized.  But {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * java.util.concurrent.ConcurrentHashMap} is "concurrent".  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * concurrent collection is thread-safe, but not governed by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * single exclusion lock.  In the particular case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * ConcurrentHashMap, it safely permits any number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * concurrent reads as well as a tunable number of concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * writes.  "Synchronized" classes can be useful when you need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * to prevent all access to a collection via a single lock, at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * the expense of poorer scalability.  In other cases in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * multiple threads are expected to access a common collection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * "concurrent" versions are normally preferable.  And
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * unsynchronized collections are preferable when either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * collections are unshared, or are accessible only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * holding other locks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * <p>Most concurrent Collection implementations (including most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * Queues) also differ from the usual java.util conventions in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * their Iterators provide <em>weakly consistent</em> rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * fast-fail traversal.  A weakly consistent iterator is thread-safe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * but does not necessarily freeze the collection while iterating, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * it may (or may not) reflect any updates since the iterator was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * <h2><a name="MemoryVisibility">Memory Consistency Properties</a></h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 *
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9242
diff changeset
   221
 * Chapter 17 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9242
diff changeset
   222
 * <cite>The Java&trade; Language Specification</cite>
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9242
diff changeset
   223
 * defines the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * <i>happens-before</i> relation on memory operations such as reads and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * writes of shared variables.  The results of a write by one thread are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * guaranteed to be visible to a read by another thread only if the write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * operation <i>happens-before</i> the read operation.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * {@code synchronized} and {@code volatile} constructs, as well as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * {@code Thread.start()} and {@code Thread.join()} methods, can form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * <i>happens-before</i> relationships.  In particular:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 *   <li>Each action in a thread <i>happens-before</i> every action in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *   thread that comes later in the program's order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *   <li>An unlock ({@code synchronized} block or method exit) of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 *   monitor <i>happens-before</i> every subsequent lock ({@code synchronized}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 *   block or method entry) of that same monitor.  And because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 *   the <i>happens-before</i> relation is transitive, all actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *   of a thread prior to unlocking <i>happen-before</i> all actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 *   subsequent to any thread locking that monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 *   <li>A write to a {@code volatile} field <i>happens-before</i> every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 *   subsequent read of that same field.  Writes and reads of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 *   {@code volatile} fields have similar memory consistency effects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 *   as entering and exiting monitors, but do <em>not</em> entail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 *   mutual exclusion locking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 *   <li>A call to {@code start} on a thread <i>happens-before</i> any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *   action in the started thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 *   <li>All actions in a thread <i>happen-before</i> any other thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 *   successfully returns from a {@code join} on that thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * The methods of all classes in {@code java.util.concurrent} and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * subpackages extend these guarantees to higher-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * synchronization.  In particular:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 *   <li>Actions in a thread prior to placing an object into any concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 *   collection <i>happen-before</i> actions subsequent to the access or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 *   removal of that element from the collection in another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 *   <li>Actions in a thread prior to the submission of a {@code Runnable}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 *   to an {@code Executor} <i>happen-before</i> its execution begins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 *   Similarly for {@code Callables} submitted to an {@code ExecutorService}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 *   <li>Actions taken by the asynchronous computation represented by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 *   {@code Future} <i>happen-before</i> actions subsequent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 *   retrieval of the result via {@code Future.get()} in another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 *   <li>Actions prior to "releasing" synchronizer methods such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 *   {@code Lock.unlock}, {@code Semaphore.release}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 *   {@code CountDownLatch.countDown} <i>happen-before</i> actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 *   subsequent to a successful "acquiring" method such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 *   {@code Lock.lock}, {@code Semaphore.acquire},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 *   {@code Condition.await}, and {@code CountDownLatch.await} on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 *   same synchronizer object in another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 *   <li>For each pair of threads that successfully exchange objects via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 *   an {@code Exchanger}, actions prior to the {@code exchange()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 *   in each thread <i>happen-before</i> those subsequent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 *   corresponding {@code exchange()} in another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 *
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   289
 *   <li>Actions prior to calling {@code CyclicBarrier.await} and
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   290
 *   {@code Phaser.awaitAdvance} (as well as its variants)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 *   <i>happen-before</i> actions performed by the barrier action, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 *   actions performed by the barrier action <i>happen-before</i> actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 *   subsequent to a successful return from the corresponding {@code await}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 *   in other threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
package java.util.concurrent;