package join;

public class JoinDemo {

	public static void main ( String[] args ) {

		Thread thread1 = new Thread(new SlowCountdown(10,""));
		Thread thread2 = new Thread(new SlowCountdown(20,"   "));

		thread1.start();
		thread2.start();

		System.out.println("waiting for " + thread2.getName() + " to finish");
		for ( ; thread2.isAlive() ; ) {
			try {
				thread2.join();
			} catch ( InterruptedException e ) {
				System.out.println("I was interrupted!");
			}
		}
		System.out.println("waiting for " + thread1.getName() + " to finish");
		for ( ; thread1.isAlive() ; ) {
			try {
				thread1.join();
			} catch ( InterruptedException e ) {
				System.out.println("I was interrupted!");
			}
		}

		System.out.println("all threads done");
	}

}
