Threads aren't a new idea: many operating systems and languages support them. But despite widespread support, threads tend to be something that everyone talks about, but few use. Programming with threads has a reputation for being tricky and nonportable.
Not so with Java. Java's thread facilities are easy to use, and--like everything else in Java--are completely portable between platforms. And that's a good thing, because it's impossible to write anything but the simplest applet without encountering threads. If you want to work with Java, you have to learn about threads.
This new edition shows you how to take full advantage of Java's thread facilities: where to use threads to increase efficiency, how to use them effectively, and how to avoid common mistakes.
Java Threadsdiscusses problems like deadlock, race condition, and starvation in detail, helping you to write code without hidden bugs. It brings you up to date with the latest changes in the thread interface for JDK 1.2.
The book offers a thorough discussion of the Thread and ThreadGroup classes, the Runnable interface, the language's synchronized operator. It explains thread scheduling ends by developing a CPUSchedule class, showing you how to implement your own scheduling policy. In addition,Java Threadsshows you how to extend Java's thread primitives. Other extended examples include classes that implement reader/writer locks, general locks, locks at arbitrary scope, and asynchronous I/O. This edition also adds extensive examples on thread pools, advanced synchronization technique, like condition variables, barriers, and daemon locks. It shows how to work with classes that are not thread safe, and pays special attention to threading issues with Swing. A new chapter shows you how to write parallel code for multiprocessor machines.
In short,Java Threadscovers everything you need to know about threads, from the simplest animation applet to the most complex applications. If you plan to do any serious work in Java, you will find this book invaluable. Examples available online. Covers Java 2.
What people are saying - Write a review
Introduction to Threading
The Java Threading API
Threading Using the Runnable Interface
The Life Cycle of a Thread
An Overview of Thread Scheduling
When Scheduling Is Important
Scheduling with Thread Priorities
Popular Scheduling Implementations
Native Scheduling Support
Other ThreadScheduling Methods
Java Thread Scheduling Examples
More on Starting Stopping and Joining
Reading Data Asynchronously
A Class to Perform Synchronization
The Synchronized Block
Return to the Banking Example
Synchronizing Static Methods
Wait and Notify
Wait and Notify
wait notify and notifyAll
wait and sleep
Static Methods Synchronization Details
Useful Examples of Java Thread Programming
Simple Synchronization Examples
A Network Server Class
The AsyncInputStream Class
Using TCPServer with AsyncInputStreams
Java Thread Scheduling
Advanced Synchronization Topics
Parallelizing for Multiprocessor Machines
Parallelizing a SingleThreaded Program
Creating Thread Groups
Thread Group Methods
Manipulating Thread Groups
Thread Groups Threads and Security
Exceptions and Errors