Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Threads and Synchronization and the fly likes what is work of join() method of class Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "what is work of join() method of class Thread" Watch "what is work of join() method of class Thread" New topic
Author

what is work of join() method of class Thread

Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
hey ranchar would you just explane about the join() method of Thread class because i unable to get it so

Regard

Arun
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24041
    
  13

If you call join() on a thread, it won't return until that thread terminates. So what join() does is wait for a thread to complete.

Imagine you want to start ten worker threads, then do something when all ten are finished. You'd create the ten threads, store them in an array, the start them all. Then you use a for loop to call join() on each one. When the for loop completes, all then threads have finished their work.


[Jess in Action][AskingGoodQuestions]
Anil Chatty
Greenhorn

Joined: Jun 12, 2007
Posts: 21
the currently executing thread stops until the thread on which join() was called completes.


SCJP 5.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: what is work of join() method of class Thread
 
Similar Threads
join()
join()
Threads..join() method
returning data from a running thread