ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/package.html
Revision: 1.11
Committed: Mon Nov 10 17:31:23 2003 UTC (20 years, 6 months ago) by dl
Content type: text/html
Branch: MAIN
CVS Tags: JSR166_DEC9_PRE_ES_SUBMIT, JSR166_DEC9_POST_ES_SUBMIT
Changes since 1.10: +5 -5 lines
Log Message:
Wording and typo cleanup pass

File Contents

# Content
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html> <head>
3 <title>Concurrency Utilities</title>
4 </head>
5
6 <body>
7
8 <p> 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 <tt>locks</tt> and
13 <tt>atomic</tt> packages.
14
15 <h2>Executors</h2>
16
17 {@link java.util.concurrent.Executor} is a simple standardized
18 interface for defining custom thread-like subsystems, including thread
19 pools, asynchronous IO, and lightweight task frameworks. Depending on
20 which concrete Executor class is being used, tasks may execute in a
21 newly created thread, an existing task-execution thread, or the thread
22 calling <tt>execute()</tt>, and may execute sequentially or
23 concurrently.
24
25 <p> {@link java.util.concurrent.ExecutorService} provides a more
26 complete framework for executing Runnables. An ExecutorService
27 manages queueing and scheduling of tasks, and allows controlled
28 shutdown. The two primary implementations of ExecutorService are
29 {@link java.util.concurrent.ThreadPoolExecutor}, a tunable and
30 flexible thread pool and {@link
31 java.util.concurrent.ScheduledExecutor}, which adds support for
32 delayed and periodic task execution. The {@link
33 java.util.concurrent.Executors} class provides factory methods for the
34 most common kinds and configurations of Executors, as well as a few
35 utility methods for using them.
36
37 <p> Executors may be used with threads that compute functions
38 returning results. A {@link java.util.concurrent.Future} returns the
39 results of a {@link java.util.concurrent.Callable}, the result-bearing
40 analog of {@link java.lang.Runnable}. Instances of concrete class
41 {@link java.util.concurrent.FutureTask} may be submitted to Executors
42 to asynchronously start a potentially long-running computation, query
43 to determine if its execution has completed, or cancel it. The {@link
44 java.util.concurrent.CancellableTask} class provides similar control
45 for actions that do not bear results.
46
47 <h2>Queues</h2>
48
49 The java.util.concurrent {@link
50 java.util.concurrent.ConcurrentLinkedQueue} class supplies an
51 efficient scalable thread-safe non-blocking FIFO queue. Five
52 implementations in java.util.concurrent support the extended {@link
53 java.util.concurrent.BlockingQueue} interface, that defines blocking
54 versions of put and take: {@link
55 java.util.concurrent.LinkedBlockingQueue}, {@link
56 java.util.concurrent.ArrayBlockingQueue}, {@link
57 java.util.concurrent.SynchronousQueue}, {@link
58 java.util.concurrent.PriorityBlockingQueue}, and {@link
59 java.util.concurrent.DelayQueue}. The different classes cover the most
60 common usage contexts for producer-consumer, messaging, parallel
61 tasking, and related concurrent designs.
62
63
64 <h2>Timing</h2>
65
66 The {@link java.util.concurrent.TimeUnit} class provides multiple
67 granularities (including nanoseconds) for specifying and controlling
68 time-out based operations. Most classes in the package contain
69 operations based on time-outs in addition to indefinite waits. In all
70 cases that time-outs are used, the time-out specifies the minimum time
71 that the method should wait before indicating that it
72 timed-out. Implementations make a &quot;best effort&quot; to detect
73 time-outs as soon as possible after they occur. However, an indefinite
74 amount of time may elapse between a time-out being detected and a
75 thread actually executing again after that time-out.
76
77 <h2>Synchronizers</h2>
78
79 Five classes aid common special-purpose synchronization idioms.
80 {@link java.util.concurrent.Semaphore} is a classic concurrency tool.
81 {@link java.util.concurrent.CountDownLatch} is very simple yet very
82 common utility for blocking until a given number of signals, events,
83 or conditions hold. A {@link java.util.concurrent.CyclicBarrier} is a
84 resettable multiway synchronization point common in some styles of
85 parallel programming. An {@link java.util.concurrent.Exchanger} allows
86 two threads to exchange objects at a rendezvous point.
87
88 <h2>Concurrent Collections</h2>
89
90 Besides Queues, this package supplies a few Collection implementations
91 designed for use in multithreaded contexts: {@link
92 java.util.concurrent.ConcurrentHashMap}, {@link
93 java.util.concurrent.CopyOnWriteArrayList}, and {@link
94 java.util.concurrent.CopyOnWriteArraySet}.
95
96 <p>The "Concurrent" prefix used with some classes in this package is a
97 shorthand indicating several differences from similar "synchronized"
98 classes. For example <tt>java.util.Hashtable</tt> and
99 <tt>Collections.synchronizedMap(new HashMap())</tt> are
100 synchronized. But {@link java.util.concurrent.ConcurrentHashMap} is
101 "concurrent". A concurrent collection is thread-safe, but not
102 governed by a single exclusion lock. In the particular case of
103 ConcurrentHashMap, it safely permits any number of concurrent reads as
104 well as a tunable number of concurrent writes. "Synchronized" classes
105 can be useful when you need to prevent all access to a collection via
106 a single lock, at the expense of poorer scalability. In other cases in
107 which multiple threads are expected to access a common collection,
108 "concurrent" versions are normally preferable. And unsynchronized
109 collections are preferable when either collections are unshared, or
110 are accessible only when holding other locks.
111
112 <p> Most concurrent Collection implementations (including most Queues)
113 also differ from the usual java.util conventions in that their Iterators
114 provide <em>weakly consistent</em> rather than fast-fail traversal. A
115 weakly consistent iterator is thread-safe, but does not necessarily
116 freeze the collection while iterating, so it may (or may not) reflect
117 any updates since the iterator was created.
118
119 </body> </html>