ThreadsDemo1public class ThreadsDemo1 extends Thread Threaded demo application, as a Threads subclass. |
Fields Summary |
---|
String | mesg | int | count |
Constructors Summary |
---|
public ThreadsDemo1(String m, int n)Construct a ThreadsDemo1 object.
count = n;
mesg = m;
setName(m + " runner Thread");
|
Methods Summary |
---|
public static void | main(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();
| void | println(java.lang.String s)
System.out.println(s);
| public void | run()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.");
|
|