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 Problem in understanding 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 "Problem in understanding join()" Watch "Problem in understanding join()" New topic
Author

Problem in understanding join()

Arpit Gadle
Ranch Hand

Joined: Dec 16, 2008
Posts: 69

Hi,
I am preparing for SCJP 6.0. I am having a problem in understanding join() method.
Can any body provide a small program demonstrating use of join().
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Arpit Gadle wrote:Hi,
I am preparing for SCJP 6.0. I am having a problem in understanding join() method.
Can any body provide a small program demonstrating use of join().


The join() method is used to wait for another thread to finish. So, when you call the join() method on a thread object, the method will not return, until the thread represented by the thread object has finished.

I am not sure what "problem in understanding" that you may be having. Or how could an example program can really help more than what I just described. Perhaps you can elaborate the issue that you are having.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Arpit Gadle
Ranch Hand

Joined: Dec 16, 2008
Posts: 69

I am clear with the definition. But was having problem in writing small example which demonstrates how join() actually works. After posting this topic, I tried for a while and wrote a program which actually shows how join() works


What this code does is, it joins the current thread (main) to thread t2. So the current thread will not become runnable until t2 has finihsed.

Where should I place call to join() so that thread t2 can join thread t3.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18132
    
    8

You want the thread which runs the Job_2 class to wait at some point during that running for t3 to terminate before continuing? Then you would call t3.join() in the Job_2 class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in understanding join()
 
Similar Threads
initialize all properties at once without using annotation fetchType eager
Theta Join
jpql, join on?
Page directive attribute
is there a difference between JOIN and INNER JOIN in JPQL ?