ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/package-info.java
Revision: 1.2
Committed: Wed Jul 29 11:55:47 2009 UTC (14 years, 10 months ago) by dl
Branch: MAIN
Changes since 1.1: +27 -9 lines
Log Message:
Updated for jsr166y additions

File Contents

# User Rev Content
1 jsr166 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/licenses/publicdomain
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 IO, 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 dl 1.2 * <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 jsr166 1.1 * <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 dl 1.2 * <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 jsr166 1.1 * <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     * Four classes aid common special-purpose synchronization idioms.
124 dl 1.2 * {@link java.util.concurrent.Semaphore} is a classic concurrency
125     * tool. {@link java.util.concurrent.CountDownLatch} is a very simple
126     * yet very common utility for blocking until a given number of
127     * signals, events, or conditions hold. A {@link
128     * java.util.concurrent.CyclicBarrier} is a resettable multiway
129     * synchronization point useful in some styles of parallel
130     * programming. A {@link java.util.concurrent.Phaser} provides a more
131     * flexible form of barrier that may be used to control phased
132     * computation among multiple threads. An {@link
133     * java.util.concurrent.Exchanger} allows two threads to exchange
134     * objects at a rendezvous point, and is useful in several pipeline
135     * designs.
136 jsr166 1.1 *
137     * <h2>Concurrent Collections</h2>
138     *
139     * Besides Queues, this package supplies Collection implementations
140     * designed for use in multithreaded contexts:
141     * {@link java.util.concurrent.ConcurrentHashMap},
142     * {@link java.util.concurrent.ConcurrentSkipListMap},
143     * {@link java.util.concurrent.ConcurrentSkipListSet},
144     * {@link java.util.concurrent.CopyOnWriteArrayList}, and
145     * {@link java.util.concurrent.CopyOnWriteArraySet}.
146     * When many threads are expected to access a given collection, a
147     * {@code ConcurrentHashMap} is normally preferable to a synchronized
148     * {@code HashMap}, and a {@code ConcurrentSkipListMap} is normally
149     * preferable to a synchronized {@code TreeMap}.
150     * A {@code CopyOnWriteArrayList} is preferable to a synchronized
151     * {@code ArrayList} when the expected number of reads and traversals
152     * greatly outnumber the number of updates to a list.
153    
154     * <p>The "Concurrent" prefix used with some classes in this package
155     * is a shorthand indicating several differences from similar
156     * "synchronized" classes. For example {@code java.util.Hashtable} and
157     * {@code Collections.synchronizedMap(new HashMap())} are
158     * synchronized. But {@link
159     * java.util.concurrent.ConcurrentHashMap} is "concurrent". A
160     * concurrent collection is thread-safe, but not governed by a
161     * single exclusion lock. In the particular case of
162     * ConcurrentHashMap, it safely permits any number of
163     * concurrent reads as well as a tunable number of concurrent
164     * writes. "Synchronized" classes can be useful when you need
165     * to prevent all access to a collection via a single lock, at
166     * the expense of poorer scalability. In other cases in which
167     * multiple threads are expected to access a common collection,
168     * "concurrent" versions are normally preferable. And
169     * unsynchronized collections are preferable when either
170     * collections are unshared, or are accessible only when
171     * holding other locks.
172     *
173     * <p>Most concurrent Collection implementations (including most
174     * Queues) also differ from the usual java.util conventions in that
175     * their Iterators provide <em>weakly consistent</em> rather than
176     * fast-fail traversal. A weakly consistent iterator is thread-safe,
177     * but does not necessarily freeze the collection while iterating, so
178     * it may (or may not) reflect any updates since the iterator was
179     * created.
180     *
181     * <h2><a name="MemoryVisibility">Memory Consistency Properties</a></h2>
182     *
183     * <a href="http://java.sun.com/docs/books/jls/third_edition/html/memory.html">
184     * Chapter 17 of the Java Language Specification</a> defines the
185     * <i>happens-before</i> relation on memory operations such as reads and
186     * writes of shared variables. The results of a write by one thread are
187     * guaranteed to be visible to a read by another thread only if the write
188     * operation <i>happens-before</i> the read operation. The
189     * {@code synchronized} and {@code volatile} constructs, as well as the
190     * {@code Thread.start()} and {@code Thread.join()} methods, can form
191     * <i>happens-before</i> relationships. In particular:
192     *
193     * <ul>
194     * <li>Each action in a thread <i>happens-before</i> every action in that
195     * thread that comes later in the program's order.
196     *
197     * <li>An unlock ({@code synchronized} block or method exit) of a
198     * monitor <i>happens-before</i> every subsequent lock ({@code synchronized}
199     * block or method entry) of that same monitor. And because
200     * the <i>happens-before</i> relation is transitive, all actions
201     * of a thread prior to unlocking <i>happen-before</i> all actions
202     * subsequent to any thread locking that monitor.
203     *
204     * <li>A write to a {@code volatile} field <i>happens-before</i> every
205     * subsequent read of that same field. Writes and reads of
206     * {@code volatile} fields have similar memory consistency effects
207     * as entering and exiting monitors, but do <em>not</em> entail
208     * mutual exclusion locking.
209     *
210     * <li>A call to {@code start} on a thread <i>happens-before</i> any
211     * action in the started thread.
212     *
213     * <li>All actions in a thread <i>happen-before</i> any other thread
214     * successfully returns from a {@code join} on that thread.
215     *
216     * </ul>
217     *
218     *
219     * The methods of all classes in {@code java.util.concurrent} and its
220     * subpackages extend these guarantees to higher-level
221     * synchronization. In particular:
222     *
223     * <ul>
224     *
225     * <li>Actions in a thread prior to placing an object into any concurrent
226     * collection <i>happen-before</i> actions subsequent to the access or
227     * removal of that element from the collection in another thread.
228     *
229     * <li>Actions in a thread prior to the submission of a {@code Runnable}
230     * to an {@code Executor} <i>happen-before</i> its execution begins.
231     * Similarly for {@code Callables} submitted to an {@code ExecutorService}.
232     *
233     * <li>Actions taken by the asynchronous computation represented by a
234     * {@code Future} <i>happen-before</i> actions subsequent to the
235     * retrieval of the result via {@code Future.get()} in another thread.
236     *
237     * <li>Actions prior to "releasing" synchronizer methods such as
238     * {@code Lock.unlock}, {@code Semaphore.release}, and
239     * {@code CountDownLatch.countDown} <i>happen-before</i> actions
240     * subsequent to a successful "acquiring" method such as
241     * {@code Lock.lock}, {@code Semaphore.acquire},
242     * {@code Condition.await}, and {@code CountDownLatch.await} on the
243     * same synchronizer object in another thread.
244     *
245     * <li>For each pair of threads that successfully exchange objects via
246     * an {@code Exchanger}, actions prior to the {@code exchange()}
247     * in each thread <i>happen-before</i> those subsequent to the
248     * corresponding {@code exchange()} in another thread.
249     *
250 dl 1.2 * <li>Actions prior to calling {@code CyclicBarrier.await} and
251     * {@code Phaser.awaitAdvance} (as well as its variants)
252 jsr166 1.1 * <i>happen-before</i> actions performed by the barrier action, and
253     * actions performed by the barrier action <i>happen-before</i> actions
254     * subsequent to a successful return from the corresponding {@code await}
255     * in other threads.
256     *
257     * </ul>
258     *
259     * @since 1.5
260     */
261     package java.util.concurrent;