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