File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Join method

Ruchika Kapoor
Greenhorn

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() ?

Thanks,
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
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
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

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.

Henry


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

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.
 
GeeCON Prague 2014
 
subject: Join method