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 Why use join() ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Why use join() ?" Watch "Why use join() ?" New topic
Author

Why use join() ?

Faisal syed
Ranch Hand

Joined: Mar 25, 2011
Posts: 35
join() Why use join() when we know our thread can finish only after the thread which we're joining? What purpose does this serve? What if I include the other thread's code in my own thread?
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 420
    
    2

Example:

Say you have 75 mins of work and you work out that 25 mins and another 50 mins can be down in parallel (multithreaded) and the results combined so
you start the 50 min job in parallel (another thread) , do your 25 min work (main thread) and join to wait for the 50 min job to complete.

Total running time 50 mins , if you did all the work in one thread as you suggest 75 mins to do both sets (its faster).


"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
suraj aryan
Greenhorn

Joined: Nov 19, 2010
Posts: 17
The main difference is if t1 thread wants to join t2 ,the time t2 is executing can be utilised by t1 also .
This cannot happen when you include t1 code in t2.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why use join() ?