O'Reilly logo

Operating Systems: Concurrent and Distributed Software Design by Tim Harris, Jean Bacon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.18. Java threads and exceptions

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required