// a thread demo
class tmp extends Thread {
	int x;
	tmp another;
	tmp (int i) {x=i;}
	public void setAnother(tmp k) { another = k;}
	public void printmymsg (int caller) 
		{System.out.println("Hi " + caller + " My id is " + x);}
	public void run() {
		while (true) {
			System.out.println(x);
			another.printmymsg(x);
			try { sleep(100); } catch (Exception e){}
		} 
	}
							
}

class ThreadDemo {
	public static void main (String args[]) {
		
		tmp t1,t2;
		t1 = new tmp(1);
		t2 = new tmp(2);
		
		t1.setAnother(t2);
		t2.setAnother(t1);

		t1.start();
		// t2.run(); // an ordinary blocking call
		t2.start();
		while (true) {
			System.out.println(3);
			try {Thread.sleep(10);}catch(Exception e){};
		}
		//System.out.println ("Main has terminated");
		
		
	}
}

