Java Reference
In-Depth Information
BlockingQueue class (an implementation of interface BlockingQueue ) we discuss in
Section 23.6 . Two other concurrency API classes that you'll use frequently are
LinkedBlockingQueue and ConcurrentHashMap (each summarized in Fig. 23.22).
The concurrency API classes are written by experts, have been thoroughly tested
and debugged, operate efficiently and help you avoid common traps and pitfalls.
Section 23.10 overviews Java's pre-built concurrent collections.
2. For advanced programmers who want to control synchronization, use the syn-
chronized keyword and Object methods wait , notify and notifyAll , which
we discuss in the optional Section 23.7.
3. Only the most advanced programmers should use Lock s and Condition s, which we
introduce in the optional Section 23.9, and classes like LinkedTransferQueue —an
implementation of interface TransferQueue —which we summarize in Fig. 23.22.
You might want to read our discussions of the more advanced features in items 2 and 3
above, even though you most likely will not use them. We explain these because:
They provide a solid basis for understanding how concurrent applications syn-
chronize access to shared memory.
By showing you the complexity involved in using these low-level features, we
hope to impress upon you the message: Use the simpler prebuilt concurrency capa-
bilities whenever possible .
23.2 Thread States and Life Cycle
At any time, a thread is said to be in one of several thread states —illustrated in the UML
state diagram in Fig. 23.1. Several of the terms in the diagram are defined in later sections.
We include this discussion to help you understand what's going on “under the hood” in a
Java multithreaded environment. Java hides most of this detail from you, greatly simplify-
ing the task of developing multithreaded applications.
new
program starts
the thread
runnable
waiting
timed waiting
terminated
blocked
Fig. 23.1 | Thread life-cycle UML state diagram.
 
 
 
Search WWH ::




Custom Search