Subclassing the Thread Class
One way to create threads is to write a separate class that subclasses the Thread class.
- The main line of execution is put in a method called run(), which overrides the method of the same name from the Thread class.
Instances of this subclass are instantiated like this:
- MyThread mt = new MyThread( );
Thread control:
- When the thread is created, it does not automatically start running. The class that creates it must call the Thread method start().
- Other methods may be called: Thread.sleep( ), Thread.yield( ), and join( ). (Note that sleep( ) and yield( ) are static methods.)