public class PingPong extends Thread
{
private String word;
private int delay;
public PingPong(String whatToSay,int delayTime)
{
word = whatToSay;
delay = delayTime;
}
public void run()
{
try
{
while(true)
{
System.out.println(word);
Thread.sleep(delay);
}
}
catch(InterruptedException e)
{
return;
}
}
public static void main(String[] args)
{
new PingPong("ping",333).start(); //1/3 s
new PingPong("Pong",1000).start();//1/1 s
}
}