Extending Thread

You can make your class runnable as a thread by extending the class java.lang.Thread. This gives the class direct access to all the thread methods defined in the Thread class. The Thread class defines a run method that you will need to override because the run method in the Thread class does not do anything but return void. The run method is empty and will not do any work for you. You must override the run method and provide the implementation for the particular application.

Listing 11.1 shows the class SimpleThread, which extends the Thread class and overrides the parent's run method.

Code Listing 11.1. Source Code for SimpleThread.java
 public class SimpleThread extends Thread { // Default Constructor public SimpleThread() ...

Get Special Edition Using Java 2 Standard Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.