// threads 

public class PingPong extends Thread {

private String word;
private int d;

public  PingPong (String whatToSay, int delayTime) {

		word = whatToSay;
		d = delayTime;
	}

public  void run ( ) {

	try {
		while (true) {

			System.out.println (word + "\n");
			sleep (d);
		}

	     }
	catch (InterruptedException e) {

		System.out.println ("exception occured\n");

		return;		// end this thread
	}

	}


public  static void main (String[] args) {

		PingPong T1 = new PingPong ("ping", 1000); 
		PingPong T2 = new PingPong ("pong", 500);

		System.out.println ("main thread starts");
		T1.start () ;
		T2.start () ;
		System.out.println ("main thread ends");
	}
}


