Java Reference
In-Depth Information
We also discussed the wait , notify , and notifyAll methods of Object . These methods
are used in a producer/consumer model where one thread is “producing” something and
another thread is “consuming” something. The object's lock must be owned by the current
thread before invoking these methods or an exception occurs at runtime.
Be sure to test your knowledge of concurrency by answering the Review Questions at
the end of the chapter. Make sure you have a good understanding of the following Exam
Essentials before you attempt the Review Questions, and good luck!
Exam Essentials
Know the two different ways to write a thread in Java. A thread in Java is created
by either extending the Thread class or writing a class that implements Runnable and
associating an instance with a new Thread .
Understand the various states of a thread and the ways that a thread can transition from
one state to another. For example, a NEW thread transitions to RUNNABLE by invoking
its start method. A RUNNABLE thread transitions to BLOCKED when attempting to acquire
an unavailable lock. A RUNNABLE thread transitions to TERMINATED upon running to
completion.
A thread cannot be started more than once. A thread can only be started
once. An attempt to start a thread that has already been started results in an
IllegalThreadStateException .
Understand the synchronized keyword. The synchronized keyword is used by a thread to
attempt to acquire an object's monitor lock. The synchronized keyword is used to write a
synchronized block of code or to denote a method as synchronized.
Understand the join method. A thread that calls join on another thread blocks until the
other thread runs to completion.
The output of a multithreaded application is indeterminate. In many situations, the out-
put is indeterminate because there are multiple possible results of the code.
Understand the producer/consumer model. Be able to answer conceptual questions about
the producer/consumer model, along with a programmatic understanding of how to use the
wait and notify methods.
Search WWH ::




Custom Search