public class FatherSonGrandsonThread extends Thread
{
	public FatherSonGrandsonThread (String name)
	{
		super(name);
	}
	
	public void run ()
	{
		System.out.println(getName() + ": I just started.");
		if (getName().equals("Son"))
		{
			FatherSonGrandsonThread grandson = new FatherSonGrandsonThread("Grandson");
			System.out.println(getName() + ": I created a son, my father's grandson.");
			grandson.start();
			System.out.println(getName() + ": I started the grandson.");
			try
			{
				grandson.join();
				System.out.println(getName() + ": Grandson is dead.");
			}
			catch(InterruptedException e)
			{
				System.out.println(getName() + ": InterruptedException caught when joining grandson! --- " + e.toString());
			}
		}
		System.out.println(getName() + ": Now I'm dying.");
	}
	
	public static void main (String[] args)
	{
		System.out.println("Father: I just started.");
		FatherSonGrandsonThread son = new FatherSonGrandsonThread("Son");
		System.out.println("Father: I created a son.");
		son.start();
		System.out.println("Father: I started the son.");
		try
		{
			son.join();
			System.out.println("Father: Son is dead, I'm dying too.");
		}
		catch(InterruptedException e)
		{
			System.out.println("Father: InterruptedException caught when joining son! --- " + e.toString());
		}
	}
}