book.html
| CD-ROM
| FAQ
| References
| Errata
| Online Tutorial
We made a lot of minor changes to the fourth printing of The Java Tutorial to fix various errors and ommissions. The changes effected over 100 pages and are too numerous and (for the most part) too trivial to list individually. So, instead we summarize:
sleep()
method. sleep()
is a class method (not an instance method).
In printings prior to the fourth, the examples in the threads lesson
called the sleep()
method from a thread instance like this:
This incorrectly implies that the instruction is puttingmyThread.sleep();
myThread
to sleep when in fact it is putting
the current thread to sleep. The examples should, in fact,
call the sleep()
method from the class like this:
The examples and text have been corrected.Thread.sleep();
notify()
method to
notify waiting threads that a certain condition had been met.
While this worked for the particular example because there is
only one producer and one consumer, this solution does not scale
to work with multiple producers and multiple consumers. A
programmer who is not going to analyze a multithreaded program
sufficiently carefully is better off using notifyAll()
.
The examples and text have been corrected.
notify()
and
wait()
methods, we claimed that those methods could
only be called within a synchronized block. The fourth printing
now states: Note: The notifyAll()
and
wait()
methods can be invoked only by the thread
that holds the lock.
book.html
| CD-ROM
| FAQ
| References
| Errata
| Online Tutorial