src/java.base/share/classes/java/util/concurrent/package-info.java
author dl
Sat, 14 Sep 2019 11:26:26 -0700
changeset 58138 1e4270f875ee
parent 52959 a35f7a452257
permissions -rw-r--r--
8225490: Miscellaneous changes imported from jsr166 CVS 2019-09 Reviewed-by: martin, alanb
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
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
    51
 * thread pools, asynchronous I/O, and lightweight task frameworks.
2
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
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   105
 * supplies an efficient scalable thread-safe non-blocking FIFO queue.
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   106
 * The {@link java.util.concurrent.ConcurrentLinkedDeque} class is
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   107
 * similar, but additionally supports the {@link java.util.Deque}
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   108
 * interface.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <p>Five implementations in {@code java.util.concurrent} support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * the extended {@link java.util.concurrent.BlockingQueue}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * interface, that defines blocking versions of put and take:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * {@link java.util.concurrent.LinkedBlockingQueue},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * {@link java.util.concurrent.ArrayBlockingQueue},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * {@link java.util.concurrent.SynchronousQueue},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * {@link java.util.concurrent.PriorityBlockingQueue}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * {@link java.util.concurrent.DelayQueue}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * The different classes cover the most common usage contexts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * for producer-consumer, messaging, parallel tasking, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * related concurrent designs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   122
 * <p>Extended interface {@link java.util.concurrent.TransferQueue},
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   123
 * and implementation {@link java.util.concurrent.LinkedTransferQueue}
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   124
 * introduce a synchronous {@code transfer} method (along with related
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   125
 * features) in which a producer may optionally block awaiting its
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   126
 * consumer.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   127
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * <p>The {@link java.util.concurrent.BlockingDeque} interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * extends {@code BlockingQueue} to support both FIFO and LIFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * (stack-based) operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * Class {@link java.util.concurrent.LinkedBlockingDeque}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * provides an implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <h2>Timing</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * The {@link java.util.concurrent.TimeUnit} class provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * multiple granularities (including nanoseconds) for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * specifying and controlling time-out based operations.  Most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * classes in the package contain operations based on time-outs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * in addition to indefinite waits.  In all cases that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * time-outs are used, the time-out specifies the minimum time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * that the method should wait before indicating that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * timed-out.  Implementations make a &quot;best effort&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * to detect time-outs as soon as possible after they occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * However, an indefinite amount of time may elapse between a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * time-out being detected and a thread actually executing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * again after that time-out.  All methods that accept timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * parameters treat values less than or equal to zero to mean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * not to wait at all.  To wait "forever", you can use a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * of {@code Long.MAX_VALUE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <h2>Synchronizers</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   154
 * Five classes aid common special-purpose synchronization idioms.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   155
 * <ul>
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.Semaphore} is a classic concurrency tool.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   158
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   159
 * <li>{@link java.util.concurrent.CountDownLatch} is a very simple yet
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   160
 * very common utility for blocking until a given number of signals,
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   161
 * events, or conditions hold.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   162
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   163
 * <li>A {@link java.util.concurrent.CyclicBarrier} is a resettable
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   164
 * multiway synchronization point useful in some styles of parallel
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   165
 * programming.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   166
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   167
 * <li>A {@link java.util.concurrent.Phaser} provides
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   168
 * a more flexible form of barrier that may be used to control phased
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   169
 * computation among multiple threads.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   170
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   171
 * <li>An {@link java.util.concurrent.Exchanger} allows two threads to
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   172
 * exchange objects at a rendezvous point, and is useful in several
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   173
 * pipeline designs.
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   174
 *
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   175
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * <h2>Concurrent Collections</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * Besides Queues, this package supplies Collection implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * designed for use in multithreaded contexts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * {@link java.util.concurrent.ConcurrentHashMap},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * {@link java.util.concurrent.ConcurrentSkipListMap},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * {@link java.util.concurrent.ConcurrentSkipListSet},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * {@link java.util.concurrent.CopyOnWriteArrayList}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * {@link java.util.concurrent.CopyOnWriteArraySet}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * When many threads are expected to access a given collection, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * {@code ConcurrentHashMap} is normally preferable to a synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * {@code HashMap}, and a {@code ConcurrentSkipListMap} is normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * preferable to a synchronized {@code TreeMap}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * A {@code CopyOnWriteArrayList} is preferable to a synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * {@code ArrayList} when the expected number of reads and traversals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * greatly outnumber the number of updates to a list.
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9266
diff changeset
   193
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * <p>The "Concurrent" prefix used with some classes in this package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * is a shorthand indicating several differences from similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * "synchronized" classes.  For example {@code java.util.Hashtable} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * {@code Collections.synchronizedMap(new HashMap())} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * synchronized.  But {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * java.util.concurrent.ConcurrentHashMap} is "concurrent".  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * concurrent collection is thread-safe, but not governed by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * single exclusion lock.  In the particular case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * ConcurrentHashMap, it safely permits any number of
42322
c3474fef4fe4 8166646: Miscellaneous changes imported from jsr166 CVS 2016-10
dl
parents: 39725
diff changeset
   203
 * concurrent reads as well as a large number of concurrent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * writes.  "Synchronized" classes can be useful when you need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * to prevent all access to a collection via a single lock, at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * the expense of poorer scalability.  In other cases in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * multiple threads are expected to access a common collection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * "concurrent" versions are normally preferable.  And
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * unsynchronized collections are preferable when either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * collections are unshared, or are accessible only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * holding other locks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 *
19428
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   213
 * <p id="Weakly">Most concurrent Collection implementations
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   214
 * (including most Queues) also differ from the usual {@code java.util}
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   215
 * conventions in that their {@linkplain java.util.Iterator Iterators}
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   216
 * and {@linkplain java.util.Spliterator Spliterators} provide
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   217
 * <em>weakly consistent</em> rather than fast-fail traversal:
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   218
 * <ul>
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   219
 * <li>they may proceed concurrently with other operations
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   220
 * <li>they will never throw {@link java.util.ConcurrentModificationException
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   221
 * ConcurrentModificationException}
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   222
 * <li>they are guaranteed to traverse elements as they existed upon
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   223
 * construction exactly once, and may (but are not guaranteed to)
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   224
 * reflect any modifications subsequent to construction.
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 18768
diff changeset
   225
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 *
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   227
 * <h2 id="MemoryVisibility">Memory Consistency Properties</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 *
32991
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents: 25859
diff changeset
   229
 * Chapter 17 of
58138
1e4270f875ee 8225490: Miscellaneous changes imported from jsr166 CVS 2019-09
dl
parents: 52959
diff changeset
   230
 * <cite>The Java&trade; Language Specification</cite> defines the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * <i>happens-before</i> relation on memory operations such as reads and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * writes of shared variables.  The results of a write by one thread are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * guaranteed to be visible to a read by another thread only if the write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * operation <i>happens-before</i> the read operation.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * {@code synchronized} and {@code volatile} constructs, as well as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * {@code Thread.start()} and {@code Thread.join()} methods, can form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * <i>happens-before</i> relationships.  In particular:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *   <li>Each action in a thread <i>happens-before</i> every action in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 *   thread that comes later in the program's order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 *   <li>An unlock ({@code synchronized} block or method exit) of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 *   monitor <i>happens-before</i> every subsequent lock ({@code synchronized}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 *   block or method entry) of that same monitor.  And because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 *   the <i>happens-before</i> relation is transitive, all actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 *   of a thread prior to unlocking <i>happen-before</i> all actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 *   subsequent to any thread locking that monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *   <li>A write to a {@code volatile} field <i>happens-before</i> every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 *   subsequent read of that same field.  Writes and reads of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 *   {@code volatile} fields have similar memory consistency effects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 *   as entering and exiting monitors, but do <em>not</em> entail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 *   mutual exclusion locking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 *   <li>A call to {@code start} on a thread <i>happens-before</i> any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 *   action in the started thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 *   <li>All actions in a thread <i>happen-before</i> any other thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 *   successfully returns from a {@code join} on that thread.
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
 * The methods of all classes in {@code java.util.concurrent} and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * subpackages extend these guarantees to higher-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * synchronization.  In particular:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 *   <li>Actions in a thread prior to placing an object into any concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 *   collection <i>happen-before</i> actions subsequent to the access or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 *   removal of that element from the collection in another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 *   <li>Actions in a thread prior to the submission of a {@code Runnable}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 *   to an {@code Executor} <i>happen-before</i> its execution begins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 *   Similarly for {@code Callables} submitted to an {@code ExecutorService}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 *   <li>Actions taken by the asynchronous computation represented by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 *   {@code Future} <i>happen-before</i> actions subsequent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 *   retrieval of the result via {@code Future.get()} in another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 *   <li>Actions prior to "releasing" synchronizer methods such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *   {@code Lock.unlock}, {@code Semaphore.release}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 *   {@code CountDownLatch.countDown} <i>happen-before</i> actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 *   subsequent to a successful "acquiring" method such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 *   {@code Lock.lock}, {@code Semaphore.acquire},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 *   {@code Condition.await}, and {@code CountDownLatch.await} on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 *   same synchronizer object in another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 *   <li>For each pair of threads that successfully exchange objects via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 *   an {@code Exchanger}, actions prior to the {@code exchange()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 *   in each thread <i>happen-before</i> those subsequent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 *   corresponding {@code exchange()} in another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 *
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   295
 *   <li>Actions prior to calling {@code CyclicBarrier.await} and
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 2
diff changeset
   296
 *   {@code Phaser.awaitAdvance} (as well as its variants)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 *   <i>happen-before</i> actions performed by the barrier action, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 *   actions performed by the barrier action <i>happen-before</i> actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 *   subsequent to a successful return from the corresponding {@code await}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 *   in other threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 *
58138
1e4270f875ee 8225490: Miscellaneous changes imported from jsr166 CVS 2019-09
dl
parents: 52959
diff changeset
   304
 * @jls 17.4.5 Happens-before Order
1e4270f875ee 8225490: Miscellaneous changes imported from jsr166 CVS 2019-09
dl
parents: 52959
diff changeset
   305
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
package java.util.concurrent;