FileDocCategorySizeDatePackage
ThreadsDemo2.javaAPI DocExample3369Sat Mar 13 19:25:36 GMT 2004None

ThreadsDemo2

public class ThreadsDemo2 extends Object implements Runnable
Threaded demo application, version 2, using Runnable.
author
Ian Darwin
version
$Id: ThreadsDemo2.java,v 1.8 2004/03/14 01:25:36 ian Exp $

Fields Summary
String
mesg
Thread
t
int
count
Constructors Summary
public ThreadsDemo2(String m, int n)
Construct a ThreadsDemo2 object

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

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

		new ThreadsDemo2("Hello from X", 10);
		new ThreadsDemo2("Hello from Y", 15);
	
voidprintln(java.lang.String s)

		System.out.println(s);
	
public voidrun()
Run does the work. We override the run() method in Runnable.

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