Thread Mechanism One: Making a Thread Subclass

1. Approach

Make a separate subclass of Thread, put the actions to be performed in the run method of the subclass, create an instance of it, and call that instance’s start method.

2. Outline

DriverClass.java

public class DriverClass extends SomeClass {
  ...
  public void startAThread() {
    // Create a Thread object
    ThreadClass thread = new ThreadClass();
    // Start it in a separate process
    thread.start();
    ...
  }
}

ThreadClass.java

public class ThreadClass extends Thread {
  public void run() {
    // Thread behavior here
  }
}

© 1996-99 Marty Hall, 1999 Lawrence M. Brown