Originally posted by adam lui: i am not quite sure what this method can do to threads. can anyone help?
It doesn't do anything to the thread that you are trying to join().
Basically, it causes the current thread, to wait until the thread, that you are trying to join with, to exits. When that thread is no longer alive, the join() method will return.
there are two froms of the join method.....................
1) final void join() throws InerruptedException
and 2) final void join(long millisex) throws InerruptedException
a call to both these methods invoed on athread will wait and not reutrn until either the thread has completed or it is timed out after the specificed time, respectively......
that is the first thread waits for the second thread to join in after completeion. A running thread t1 invokest the method join() on a thread t2.
The join has no effect if threadt2 has already completed. if t2 is alice then t1 transits to the blocked-for-join completion state. the thread t1 waits in this state until one of these occur..........
a) thread t2 completes ------ in this case t1 is enabled and when it gets to run, it will continure normally
b) thread t1 is timed out (time specified int he argument as in (2))
c) thread t1 is interrupted --------- then the InerruptedException will be thrown.........