Description:
Method Join () is used to cause the thread object that belongs to execute the run () method normally, while the current thread z is blocked indefinitely, waiting for thread x to be destroyed before continuing with the code now following Z.
Join also has a join (long) method, that is, long to set the wait time,
1, join () and synchronized
The join () method has the function of keeping threads queued, some similar to synchronized,
the difference with synchronized is that viewing the source can see that the join method is internally using the Wait () method for waiting, while synchronized uses the object monitor principle to implement synchronization.
2. Join () and sleep ()
The thread also has a sleep (long) method in addition to the Join method that can also be implemented to wait;
the difference from sleep () is that because the inner implementation of the join IS Wait (), the Join () method releases the lock, so other threads can call the thread's synchronization method.
The sleep (long) method has a feature that is not a lock, so the thread waits until the task completes before releasing the lock.
Note : The join () method may have an exception if it encounters a thread's interrupt () method, for example: A thread waits for the B thread to perform the task, and the B thread executes to half after interrupt (), which is reported Java.lang.InterruptedException exception.
At this point a thread does not terminate or is in the normal running state.