75 |
|
java.util.Collections will be introduced into java.util. Also, |
76 |
|
although it is at the borders of being in scope of JSR-166, |
77 |
|
java.util.LinkedList will be adapted to support Queue, and |
78 |
< |
a new non-thread-safe java.util.HeapPriorityQueue will be added. |
78 |
> |
a new non-thread-safe java.util.PriorityQueue will be added. |
79 |
|
|
80 |
|
<p> Five implementations in java.util.concurrent support the extended |
81 |
|
BlockingQueue interface, that defines blocking versions of put and |
97 |
|
calling threads that compute functions returning results, via |
98 |
|
Futures. This is supported in part by defining interface Callable, the |
99 |
|
argument/result analog of Runnable. |
100 |
+ |
|
101 |
+ |
<p> Executors provide a framework for executing Runnables. The |
102 |
+ |
Executor manages queueing and scheduling of tasks, and creation and |
103 |
+ |
teardown of threads. Depending on which concrete Executor class is |
104 |
+ |
being used, tasks may execute in a newly created thread, an existing |
105 |
+ |
task-execution thread, or the thread calling execute(), and may |
106 |
+ |
execute sequentially or concurrently. |
107 |
+ |
|
108 |
+ |
<p> Several concrete implementations of Executor are included in |
109 |
+ |
java.util.concurrent, including ThreadPoolExecutor, a flexible thread |
110 |
+ |
pool and ScheduledExecutor, which adds support for delayed and |
111 |
+ |
periodic task execution. Executor can be used in conjunction with |
112 |
+ |
FutureTask (which implements Runnable) to asynchronously start a |
113 |
+ |
potentially long-running computation and query the FutureTask to |
114 |
+ |
determine if its execution has completed. |
115 |
+ |
|
116 |
+ |
<p> The <tt>Executors</tt> class provides factory methods for all |
117 |
+ |
of the types of executors provided in |
118 |
+ |
<tt>java.util.concurrent</tt>. |
119 |
|
|
101 |
– |
<p> While the Executor framework is intended to be extensible the most |
102 |
– |
commonly used Executor will be ThreadExecutor, which can be configured |
103 |
– |
to act as all sorts of thread pools, background threads, etc. The |
104 |
– |
class is designed to be general enough to suffice for the vast |
105 |
– |
majority of usages, even sophisticated ones, yet also includes methods |
106 |
– |
and functionality that simplify routine usage. |
120 |
|
|
121 |
|
<h2>Locks</h2> |
122 |
|
|
123 |
|
The Lock interface supports locking disciplines that differ in |
124 |
< |
semantics (reentrant, semaphore-based, etc), and that can be used in |
124 |
> |
semantics (reentrant, fair, etc), and that can be used in |
125 |
|
non-block-structured contexts including hand-over-hand and lock |
126 |
|
reordering algorithms. This flexibility comes at the price of more |
127 |
< |
awkward syntax. Implementations include Semaphore, ReentrantMutex |
128 |
< |
FIFOSemaphore, and CountDownLatch. |
127 |
> |
awkward syntax. Implementations include ReentrantLock and |
128 |
> |
FairReentrantLock. |
129 |
|
|
130 |
|
<p> |
131 |
|
The Locks class additionally supports trylock-designs using builtin |
155 |
|
people can make the mistake of calling cond.notify instead of |
156 |
|
cond.signal. However, they will get IllegalMonitorState exceptions if |
157 |
|
they do, so they can detect the error if they ever run the code. |
145 |
– |
<p> |
146 |
– |
The implementation requires VM magic to atomically suspend and release |
147 |
– |
lock. But it is unlikely to be very challenging for JVM providers, |
148 |
– |
since most layer Java monitors on top of posix condvars or similar |
149 |
– |
low-level functionality anyway. |
158 |
|
|
151 |
– |
<h2>Atomic variables</h2> |
159 |
|
|
160 |
< |
Classes AtomicInteger, AtomicLong, AtomicDouble, AtomicFloat, and |
154 |
< |
AtomicReference provide simple scalar variables supporting |
155 |
< |
compareAndSwap (CAS) and related atomic operations. These are |
156 |
< |
desparately needed by those performing low-level concurrent system |
157 |
< |
programming, but much less commonly useful in higher-level frameworks. |
160 |
> |
<h2>Atomic variables</h2> |
161 |
|
|
162 |
+ |
The atomic subpackage includes a small library of classes, including |
163 |
+ |
AtomicInteger, AtomicLong, and AtomicReference that support variables |
164 |
+ |
performinf compareAndSet (CAS) and related atomic operations. |
165 |
|
|
166 |
|
<h2>Timing</h2> |
167 |
|
|
168 |
|
Java has always supported sub-millisecond versions of several native |
169 |
|
time-out-based methods (such as Object.wait), but not methods to |
170 |
|
actually perform timing in finer-grained units. We address this by |
171 |
< |
introducing class Clock, which provides multiple granularities for |
171 |
> |
introducing class TimeUnit, which provides multiple granularities for |
172 |
|
both accessing time and performing time-out based operations. |
173 |
|
|
174 |
|
|
175 |
|
<h2>Synchronizers</h2> |
176 |
|
|
177 |
|
Five classes aid common special-purpose synchronization idioms. |
178 |
< |
Semaphores and FifoSemaphores are classic concurrency tools. Latches |
179 |
< |
are very simple yet very common objects useful for blocking until a |
180 |
< |
single signal, event, or condition holds. CyclicBarriers are |
181 |
< |
resettable multiway synchronization points very common in some styles |
182 |
< |
of parallel programming. Exchangers allow two threads to exchange |
183 |
< |
objects at a rendezvous point. |
178 |
> |
Semaphores and FairSemaphores are classic concurrency tools. |
179 |
> |
CountDownLatches are very simple yet very common objects useful for |
180 |
> |
blocking until a single signal, event, or condition holds. |
181 |
> |
CyclicBarriers are resettable multiway synchronization points very |
182 |
> |
common in some styles of parallel programming. Exchangers allow two |
183 |
> |
threads to exchange objects at a rendezvous point. |
184 |
|
|
185 |
|
|
186 |
|
<h2>Concurrent Collections</h2> |
187 |
|
|
188 |
|
JSR 166 will supply a few Collection implementations designed for use |
189 |
< |
in multithreaded contexts: ConcurrentHashTable, CopyOnWriteArrayList, |
189 |
> |
in multithreaded contexts: ConcurrentHashMap, CopyOnWriteArrayList, |
190 |
|
and CopyOnWriteArraySet. |
191 |
|
|
192 |
|
<h2>Uncaught Exception Handlers</h2> |
197 |
|
too inflexible in many multithreaded programs. (Note that the combination |
198 |
|
of features in JSR 166 make ThreadGroups even less likely to |
199 |
|
be used in most programs. Perhaps they will eventually be deprecated.) |
200 |
< |
<p> |
201 |
< |
Additionally, ThreadLocals will now support a means to |
202 |
< |
remove a ThreadLocals, which is needed in some thread-pool and |
203 |
< |
worker-thread designs. |
200 |
> |
|
201 |
> |
<p> Additionally, ThreadLocals will now support a means to remove a |
202 |
> |
ThreadLocal, which is needed in some thread-pool and worker-thread |
203 |
> |
designs. |
204 |
|
|
205 |
|
<hr> |
206 |
|
<address><A HREF="http://gee.cs.oswego.edu/dl">Doug Lea</A></address> |