O'Reilly logo

Java, A Beginner’s Guide, 5th Edition by Herbert Schildt

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

Creating a Thread

You create a thread by instantiating an object of type Thread. The Thread class encapsulates an object that is runnable. As mentioned, Java defines two ways in which you can create a runnable object:

Image You can implement the Runnable interface.

Image You can extend the Thread class.

Most of the examples in this chapter will use the approach that implements Runnable. However, Try This 11-1 shows how to implement a thread by extending Thread. Remember: Both approaches still use the Thread class to instantiate, access, and control the thread. ...

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