This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Usage of Join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Usage of Join" Watch "Usage of Join" New topic
Author

Usage of Join

Harish Narayana
Greenhorn

Joined: Mar 29, 2010
Posts: 3
When do we use Join in Multithreading


Regards,
Harish
Rahul Kumar Tiwari
Greenhorn

Joined: Jun 09, 2008
Posts: 14
Harish Narayana wrote:When do we use Join in Multithreading


Suppose There is a two thread A and B. and if you started both thread by A.start(), and B.Start(). After that you see that both thread start and work according to the thread scheduler. But during this run if you want that B thread will complete their execution before A thread then write code B.join(). This method join the thread B to to the execution pool of thread A and complete their execution first. and after that A will run.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3029
    
  35

And, welcome to JavaRanch

This is an example for what Rahul said. There are three overloaded versions of this method. You can find them in the documentation of java.lang.Thread class.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Harish Narayana
Greenhorn

Joined: Mar 29, 2010
Posts: 3
Hi Rahul,
Thanks.
It will be very helpful if I get a real time example.
sood rahul
Greenhorn

Joined: Jun 30, 2010
Posts: 3
We use join() whenever we need to attach a thread at the end of another thread.

For eg. Suppose there are two threads : t1 and current thread(main thread) and we invoke start method on t1 and write t1.join();
This will join the current thread(main thread) at the end of thread t1.
As soon as this statement is executed main thread waits for thread t1 to finish.


Rahul Sood
Harish Narayana
Greenhorn

Joined: Mar 29, 2010
Posts: 3
Thanks a ton Devaka Cooray
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Usage of Join
 
Similar Threads
earn without working
WA #1.....word association
Urgent......Info required Infosys
Experience w/o depth
SCJWSD online Group study