O'Reilly logo

Java Thread Programming by Paul Hyde

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

Chapter 2. A Simple Two-Thread Example

IN THIS CHAPTER

This chapter shows just how simple it is to get a new thread up and running in a tiny Java application. The first thread is the "main" thread that is always spawned by the Java Virtual Machine (JavaVM) and starts an application. This main thread then spawns the second thread. Each of these threads will print its messages to the console to demonstrate that they both appear to be running simultaneously.

The steps to spawn a new thread in this chapter's example are

  • Extend the java.lang.Thread class.

  • Override the run() method in this subclass of Thread.

  • Create an instance of this new class.

  • Invoke ...

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