A thread is a unit of program execution that runs independently from other threads. Java programs may consist of multiple threads of execution that behave as if they were running on independent CPUs, even when the host computer actually has only a single CPU. In many programming languages, multithreading capabilities are added on as an afterthought. In Java, however, they are integrated tightly with the language and its core packages:
The use of threads is common in Java programming; it is not possible to confine a discussion of them to just one chapter. We'll start with some simple examples in this chapter. We'll see threads again in Chapter 5, where they are quite useful for writing network server programs that can respond to multiple client requests simultaneously. Threads also appear in Chapter 12, and then again in Chapter 16, where they are used to produce animation effects. |