Basic HTML version of Foils prepared 17 Nov 97

Foil 5 Subclassing the Thread Class

From Java Tutorial, July 1, 1996 CEWES Tutorial, CPS606, JSU Class CSC499 -- July 22-25 1997, Fall 97. by Nancy J. McCracken,Geoffrey C. Fox, Tom Scavo

Thread Examples for Foil 5
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( long ), Thread.yield(), suspend(), resume(), stop(), and join(). (Note that sleep( long ) and yield() are static methods.)



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998