Basic HTML version of Foils prepared Sept 21 1998

Foil 5 Subclassing the Thread Class

From Java Tutorial 98- 4: Multi-Treading, Useful Java Classes, I/O and Networking NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

Thread Examples for Foil 5
1 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.
2 Instances of this subclass are instantiated like this:
  • MyThread mt = new MyThread( );
3 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( ), suspend( ), resume( ), stop( ), and join( ). (Note that sleep( ) and yield( ) are static methods.)

in Table To:


© 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 Sat Nov 28 1998