FileDocCategorySizeDatePackage
ThreadsDemo3.javaAPI DocExample3269Sat Mar 13 19:24:06 GMT 2004None

ThreadsDemo3

public class ThreadsDemo3 extends Object
Threaded demo application, using inner class as Runnable.
author
Ian Darwin
version
1.0

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

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

		count = n;
		mesg  = m;
		t = new Thread(new Runnable() {
			public void run() {
				while (count-- > 0) {
					println(mesg);
					try {
						Thread.sleep(100);	// 100 msec
					} catch (InterruptedException e) {
						return;
					}
				}
				println(mesg + " thread all done.");
			}
		});
		t.setName(m + " runner Thread");
		t.start();
	
Methods Summary
public static voidmain(java.lang.String[] argv)
Main program, test driver for ThreadsDemo3 class.

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

		System.out.println(s);