@@ -0,0 +1,1228 @@
+// Use join().%0A%0Aclass MyThread implements Runnable %7B%0A%09int count;%0A%09Thread thrd;%0A %0A%09// Construct a new thread.%0A%09MyThread(String name) %7B%0A%09%09thrd = new Thread(this, name);%0A%09%09count = 0;%0A%09%09thrd.start(); // start the thread%0A%09%7D%0A %0A%09// Begin execution of new thread.%0A%09public void run() %7B%0A%09%09System.out.println(thrd.getName() + %22 starting.%22);%0A%09%09try %7B%0A%09%09%09do %7B%0A%09%09%09%09Thread.sleep(100);%0A%09%09%09%09System.out.println(%22In %22 + thrd.getName() + %22, count is %22 + count);%0A%09%09%09%09count++;%0A%09%09%09%7D while(count %3C 10);%0A%09%09%7D%0A%09%09catch(InterruptedException exc) %7B%0A%09%09%09System.out.println(thrd.getName() + %22 interrupted.%22);%0A%09%09%7D%0A%09%09System.out.println(thrd.getName() + %22 terminating.%22);%0A%09%7D%0A%7D%0A %0Aclass JoinThreads %7B%0A%09public static void main(String args%5B%5D) %7B%0A%09%09System.out.println(%22Main thread starting.%22);%0A %0A%09%09MyThread mt1 = new MyThread(%22Child #1%22);%0A%09%09MyThread mt2 = new MyThread(%22Child #2%22);%0A%09%09MyThread mt3 = new MyThread(%22Child #3%22);%0A %0A%09%09try %7B%0A%09%09%09mt1.thrd.join();%0A%09%09%09System.out.println(%22Child #1 joined.%22);%0A%09%09%09mt2.thrd.join();%0A%09%09%09System.out.println(%22Child #2 joined.%22);%0A%09%09%09mt3.thrd.join();%0A%09%09%09System.out.println(%22Child #3 joined.%22);%0A%09%09%7D%0A%09%09catch(InterruptedException exc) %7B%0A%09%09%09System.out.println(%22Main thread interrupted.%22);%0A%09%09%7D%0A %0A%09%09System.out.println(%22Main thread ending.%22);%0A%09%7D%0A%7D%0A

Use join() in thread