March 2003
Intermediate to advanced
912 pages
27h 17m
English
In Java, threads are created from a class which either inherits from the class Thread or implements the interface Runnable. In either case we specify the activity to be carried out by providing a run method. In the case of a thread inheriting from the Thread class, the run method overrides the run method of Thread, which otherwise has an empty method body. Producing threads via the mechanism of implementing the interface Runnable allows us to produce a class which can be used to create threads whilst still being able to inherit from some class other than Thread. Java only has single inheritance.
The program in Figure 4.32 explicitly creates two threads, using a thread that specializes Thread. The program in ...