Basic HTML version of Foils prepared 18 May 97

Foil 4 How to Use Threads from a Class

From Java Tutorial - Spring 1997 Part 4: Multithreading, useful Java classes, I/O, Networking, and the future Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


1 One can implement threads in two ways
  • Firstly subclassing the Thread class and overriding its run() method
  • Secondly by creating a Thread with a Runnable object (i. e. that implements Runnable interface)
2 Only the second way is possible for applets as these already extend Applet class and so cannot multiply inherit from the Thread class
3 Threads must have a run method which is code Thread executes.
4 If you are using first way, this is written for this particular thread and overrides run() in Thread class
5 In second way, the created Thread automatically takes its run() method to be the run method of the applet

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 Thu Jan 8 1998