Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

The Java Threads API makes it to print media

Read this detailed review of O'Reilly's 'Java Threads' to find out if you should invest in a copy

  • Print
  • Feedback
Java Threads isn't your run of the mill Teach Yourself Java in X Days type of book. As Scott Oaks and Henry Wong, the authors of Java Threads, explain, "This book belongs to the second wave of Java books: because it covers only a single topic, it has the luxury of explaining in deeper detail how Java's threads can be used." And this book does indeed delve into deep detail. Considering that Java's multithreading capabilities are neatly encapsulated in barely more than a single class -- java.lang.Thread and class Object's wait() and notify() methods -- and are supported by the language itself via a single keyword, synchronized, it follows that Java Threads's 250-odd pages explore many a dark multithreaded corner.

In this review I'll provide a blow-by-blow account of each of the eight chapters and four appendices, followed by a few miscellaneous items of note for anyone considering purchasing this book.

Java Threads

Java Threads
http://www.ora.com/catalog/jthreads/
ISBN 1-56592-216-6, 268 pages 9.95



Chapter and verse

Chapter 1 is the obligatory introduction to the subject matter. It explains the difference between multitasking and multithreading and why, contrary to most other programming languages, threading is so important to Java programming. The answer to the latter question simply being that all Java I/O is synchronous and that you need extra threads to avoid your applications screeching to an immediate halt whenever they access the Internet, read files, or wait for some form of timeout.

Chapter 2, "The Java Threading API," introduces the Thread class and the associated, pivotal Runnable interface. The authors examine the start(), stop(), and sleep() using a simple, multithreaded applet example, and then switch the focus to the join() method, which is used to wait for the completion of some other thread.

At this point, I think it is worth mentioning two things about the examples provided with this book: first, the book does not include a disk (floppy or CD) of source code. My initial response to this discovery was quite positive, figuring I'd just head over to the O'Reilly Web site and pick up whatever I needed; unfortunately, there is no link to such a site. My second gripe is that many of the programs are incomplete (that is, they won't compile because they are not meant to be compilable examples) or hypothetical in nature (where 90 percent of the program is left to the reader's imagination). In short, the examples do not provide insight into the behavior of running threads. Worse, because you cannot check any of the examples, you are sometimes left reading large amounts of text and code "on faith."

Chapter 2 also introduces the threading pitfall par excellence: race conditions. Readers follow along as the authors develop an AsyncReadSocket class that loses data due to a (purposely) naive lack of protection against multithreaded access of this network programming class. (Yes, the authors are Unix programmers, so they think nothing of relying on your development platform being permanently connected to a TCP/IP network, or using some advanced socket programming to make a point about multithreading. To mortals with dial-up access or novices in the art of TCP/IP programming: tough luck.)

  • Print
  • Feedback

Resources