File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Join method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Join method" Watch "Join method" New topic

Join method

Ruchika Kapoor

Joined: Oct 03, 2004
Posts: 22
join() is required when one thread T1 must do its job before thread T2 can complete its work.
So in a way we want the threads to work sequentially, one after another. But this can also be done by putting the logic in two different methods and calling them sequentially. Then what is the use of join() ?

Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 692
Why couldn't the two threads work in parallel? With savings in elapsed time if the underlying system actually allowed parallel processing. There would be no savings in elapsed time if the jobs are done sequentially.
Henry Wong

Joined: Sep 28, 2004
Posts: 20517

Agree with Norm. Just because the join() method is used, doesn't mean that the operation is sequential -- it could be a parallel operation, that has to meetup at a point, before it can continue the next phase.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
ranjeev singh

Joined: Jul 21, 2008
Posts: 1
The simple example can be - thread T1 does some complex computation and the result is used by thread T2. Unless T1 has completed its job, T2 can not use the computed value. Here T2 can wait for T1 to die. In this scenario use T1.join(). Hope this clarifies.
I agree. Here's the link:
subject: Join method
jQuery in Action, 3rd edition