class MyTask implements Runnable
{
private int delay;
private int count;
private String name;
public MyTask(String name, int delay, int count)
{
this.delay = delay;
this.count = count;
this.name = name;
}
public void run()
{
for (int i = 0; i < count; ++i)
{
try
{
Thread.sleep(delay);
System.out.println(name);
}
catch (InterruptedException x)
{
// Won't happen in this example
}
}
}
}
class Independent4
{
public static void main(String[] args)
{
Thread t1 = new Thread(new MyTask("DessertTopping", 100, 8));
Thread t2 = new Thread(new MyTask("FloorWax", 200, 4));
t1.start();
t2.start();
}
}
End of Listing