FileDocCategorySizeDatePackage
ThreadsDemo1.javaAPI DocExample1107Sun Apr 29 11:08:58 BST 2001None

ThreadsDemo1

public class ThreadsDemo1 extends Thread
Threaded demo application, as a Threads subclass.
author
Ian Darwin
version
1.0

Fields Summary
String
mesg
int
count
Constructors Summary
public ThreadsDemo1(String m, int n)
Construct a ThreadsDemo1 object.

param
String m Message to display
param
int n How many times to display it

		count = n;
		mesg  = m;
		setName(m + " runner Thread");
	
Methods Summary
public static voidmain(java.lang.String[] argv)
Main program, test driver for ThreadsDemo1 class.

		// could say: new ThreadsDemo1("Hello from X", 10).run();
		// could say: new ThreadsDemo1("Hello from Y", 15).run();
		// But then it wouldn't be multi-threaded!
		new ThreadsDemo1("Hello from X", 10).start();
		new ThreadsDemo1("Hello from Y", 15).start();
	
voidprintln(java.lang.String s)

		System.out.println(s);
	
public voidrun()
Run does the work: print a message, "count" number of times

		while (count-- > 0) {
			println(mesg);
			try {
				Thread.sleep(100);	// 100 msec
			} catch (InterruptedException e) {
				return;
			}
		}
		println(mesg + " all done.");