Thread.join() is the most basic mechanism of inter-thread synchronization in Java.
Thread.join() Method
The calling thread goes into wating state. It waits for the referenced thread to terminate.
Thread.join() throws InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
The calling thread goes into wating state. It Waits at most millis milliseconds for the referenced thread to die. A timeout of 0 means to wait forever.
This method is very useful to prevent the calling thread from waiting too long.