T1.java
import java.io.*;
/**
Print clown names from three threads.
*/
public class T1
{
public static void main(String[] argv)
{
Thread one = new T1_thread("Bozo",200);
Thread two = new T1_thread("Homey",300);
Thread three = new T1_thread("Happy",500);
System.out.println("Press ENTER when you're satisfied...");
one.start();
two.start();
three.start();
try {
System.in.read();
System.out.println("ENTER pressed.");
}
catch(IOException e) {
System.out.println("Exception: " + e);
}
System.out.println("Ending main()...");
}
}
class T1_thread extends Thread
{
public T1_thread(String name,int delay)
{
this.name = name;
this.delay = delay;
setDaemon(true);
}
public void run()
{
try {
while (!interrupted()) {
System.out.println(name);
sleep(delay);
}
}
catch(InterruptedException e) {
System.out.println(e + " interrupted!");
}
}
private String name;
private int delay;
}