/* * Illustrates thread join method */ package threads; public class TaskThree implements Runnable{ private String message; public TaskThree(String message) { this.message = message; } public void run() { int i=0; while(++i<=100) System.out.println(message + " " + i); } public static void main(String[] args) { Thread threadOne = new Thread(new TaskThree("First")); threadOne.start(); Thread threadTwo = new Thread(new TaskThree("Second")); threadTwo.start(); // main thread will block until first thread is done try { threadOne.join(); } catch(InterruptedException e){}; System.out.println("main thread done"); } }