Wait For Completion Of Thread In Java
Chapter:
Thread
Last Updated:
13-08-2016 13:10:01 UTC
Program:
/* ............... START ............... */
public class JavaCompletionOfThread {
public static void main(String a[]) throws Exception {
MyThreadExample tt1 = new MyThreadExample(50);
MyThreadExample tt2 = new MyThreadExample(75);
Thread t1 = new Thread(tt1, "Test thread 1");
Thread t2 = new Thread(tt2, "Test thread 2");
t1.start();
t2.start();
t1.join();
t2.join();
}
}
class MyThreadExample implements Runnable {
int i;
MyThreadExample(int i) {
super();
this.i = i;
}
public void run() {
System.out.println(Thread.currentThread().getName() + " " + i);
}
}
/* ............... END ............... */
Output
Test thread 2 75
Test thread 1 50
Tags
Wait For Completion Of Thread, Java, Thread