Java Reference
In-Depth Information
This version produces output that is similar to the previous version, except that main( )
ends as soon as the other threads finish. The difference is that it uses isAlive( ) to wait for
the child threads to terminate. Another way to wait for a thread to finish is to call join( ) ,
shown here:
final void join( ) throws InterruptedException
This method waits until the thread on which it is called terminates. Its name comes from
the concept of the calling thread waiting until the specified thread joins it. Additional forms
of join( ) allow you to specify a maximum amount of time that you want to wait for the
specified thread to terminate.
Here is a program that uses join( ) to ensure that the main thread is the last to stop:
Search WWH ::




Custom Search