ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jdk7/java/util/concurrent/package-info.java
Revision: 1.2
Committed: Mon Mar 4 16:09:25 2013 UTC (11 years, 2 months ago) by jsr166
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
improve javadoc anchored text

File Contents

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