Thread thdA = new Thread(r);
Thread thdB = new Thread(r);
Listing4-18 revealsthatThreadsAandBexecute Thread.sleep(100); tosleep
following partial output reveals:
A thread will occasionally start another thread to perform a lengthy calculation,
download a large file, or perform some other time-consuming activity. After finishing
the worker thread and waits for the worker thread to finish and die.
calls Thread 's isAlive() methodontheworkerthread's Thread objectandsleeps
for a certain length of time when this method returns true. However, Listing 4-19
demonstrates a less verbose alternative: the join() method.
Listing 4-19. Joining the default main thread with a background thread
public static void main(String args)