Basic HTML version of Foils prepared Sept 21 1998

Foil 11 Introduction to Threads

From Java Tutorial 98- 3: Graphics and the Abstract Windowing Toolkit NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken


A thread is a single sequential flow of control within a process.
If a process has more than one thread, then each thread executes concurrently.
Any Java applet that has extensive execution or loops to repaint the window must run as a concurrent thread with the browser window.
To make an applet with a thread:
  • Change your applet definition to add "implements Runnable", the interface for threads.
  • Include an instance variable for the thread of your applet.
  • Have a start() method that creates a thread and starts it running and a stop() method which stops it running.
  • Implement a run() method containing the body of your applet code.



© 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