FileDocCategorySizeDatePackage
ThreadSync.javaAPI DocExample3351Sun Feb 08 21:34:08 GMT 2004None

ThreadSync

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

Fields Summary
String
mesg
int
count
Constructors Summary
public ThreadSync(String m, int n)
Construct a ThreadSync 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 ThreadSync class.

		new ThreadSync("Hello from X", 10).start();
		new ThreadSync("Hello from Y", 15).start();
	
synchronized 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.");