ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/package.html
Revision: 1.1
Committed: Tue Jul 8 00:46:35 2003 UTC (20 years, 11 months ago) by dl
Content type: text/html
Branch: MAIN
CVS Tags: JSR166_PRELIMINARY_TEST_RELEASE_2
Log Message:
Locks in subpackage; fairness params added

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> Package java.util.concurrent contains utility classes commonly
9 useful in concurrent programming. Like package java.util, it includes
10 a few small standardized extensible frameworks, as well as some
11 classes that provide useful functionality and are otherwise tedious or
12 difficult to implement. Here are brief descriptions of the main
13 components. See also the <tt>locks</tt> and <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, asynch-IO, and lightweight task frameworks. Depending on which
20 concrete Executor class is being used, tasks may execute in a newly
21 created thread, an existing task-execution thread, or the thread
22 calling <tt>execute()</tt>, and may execute sequentially or
23 concurrently. Executors also standardize ways of calling threads that
24 compute functions returning results, via a {@link
25 java.util.concurrent.Future}. This is supported in part by defining
26 interface {@link java.util.concurrent.Callable}, the argument/result
27 analog of Runnable.
28
29 <p> {@link java.util.concurrent.ExecutorService} provides a more
30 complete framework for executing Runnables. An ExecutorService
31 manages queueing and scheduling of tasks, and allows controlled
32 shutdown. The two primary implementations of ExecutorService are
33 {@link java.util.concurrent.ThreadPoolExecutor}, a highly tunable and
34 flexible thread pool and {@link
35 java.util.concurrent.ScheduledExecutor}, which adds support for
36 delayed and periodic task execution. These, and other Executors can
37 be used in conjunction with a {@link java.util.concurrent.FutureTask}
38 to asynchronously
39 start a potentially long-running computation and query the FutureTask
40 to determine if its execution has completed, or cancel it.
41
42 <p> The {@link java.util.concurrent.Executors} class provides factory
43 methods for the most common kinds and styles of Executors, as well as
44 a few utilities methods for using them.
45
46 <h2>Queues</h2>
47
48 The java.util.concurrent {@link
49 java.util.concurrent.ConcurrentLinkedQueue} class supplies an
50 efficient sclable thread-safe non-blocking FIFO queue.
51
52 <p> Five implementations in java.util.concurrent support the extended
53 {@link java.util.concurrent.BlockingQueue} interface, that defines
54 blocking 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}.
60
61
62 <h2>Timing</h2>
63
64 The {@link java.util.concurrent.TimeUnit} class provides multiple
65 granularities (including nanoseconds) for both accessing time and
66 performing time-out based operations.
67
68 <h2>Synchronizers</h2>
69
70 Five classes aid common special-purpose synchronization idioms.
71 {@link java.util.concurrent.Semaphore} and {@link
72 java.util.concurrent.FairSemaphore} are classic concurrency tools.
73 {@link java.util.concurrent.CountDownLatch} is very simple yet very
74 common utility for blocking until a single signal, event, or condition
75 holds. A {@link java.util.concurrent.CyclicBarrier} is a resettable multiway
76 synchronization point common in some styles of parallel
77 programming. An {@link java.util.concurrent.Exchanger} allows two
78 threads to exchange objects at a rendezvous point.
79
80 <h2>Concurrent Collections</h2>
81
82 Besides Queues, this package supplies a few Collection implementations
83 designed for use in multithreaded contexts: {@link
84 java.util.concurrent.ConcurrentHashMap}, {@link
85 java.util.concurrent.CopyOnWriteArrayList}, and {@link
86 java.util.concurrent.CopyOnWriteArraySet}.
87
88 <p>The "Concurrent" prefix for classes is a shorthand
89 indicating several differences from similar "synchronized"
90 classes. For example <tt>java.util.Hashtable</tt> and
91 <tt>Collections.synchronizedMap(new HashMap())</tt> are
92 synchronized. But {@link
93 java.util.concurrent.ConcurrentHashMap} is "concurrent".
94 A concurrent collection (among other kinds of classes) is
95 thread-safe, but not governed by a single exclusion lock. So, in the
96 particular case of ConcurrentHashMap, it safely permits any number of
97 concurrent reads as well as a tunable number of concurrent writes.
98 There may still be a role for "synchronized" classes in some
99 multithreaded programs -- they can sometimes be useful when you need
100 to prevent ALL access to a collection via a single lock, at the
101 expense of much poor scalability. In all other cases, "concurrent"
102 versions are normally preferable.
103
104 <p> Most concurrent Collection implementations (including most Queues)
105 also differ from the usual java.util conventions in that their Iterators
106 provide <em>weakly consistent</em> rather than fast-fail traversal. A
107 weakly consistent iterator is thread-safe, but does not necessarily
108 freeze the collection while iterating, so it may (or may not) reflect
109 any updates since the iterator was created.
110
111
112
113
114 <hr>
115 <address><A HREF="http://gee.cs.oswego.edu/dl">Doug Lea</A></address>
116 <!-- hhmts start --> Last modified: Mon Jul 7 20:32:42 EDT 2003 <!-- hhmts end -->
117 </body> </html>