T2.java
import java.io.*;
/**
Print clown names from three threads.
Removed the call to setDaemon(); threads should continue after
main() exits.
*/
public class T2 extends Thread
{
public static void main(String[] argv)
{
Thread one = new T2_thread("Bozo",200);
Thread two = new T2_thread("Homey",300);
Thread three = new T2_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 T2_thread extends Thread
{
public T2_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;
}