aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes join() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "join()" Watch "join()" New topic
Author

join()

adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186
i am not quite sure what this method can do to threads. can anyone help?


boolean b = true;<br />System.out.println ("I believe in Java.<br />Java will make my dream come " + b);
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Originally posted by adam lui:
i am not quite sure what this method can do to threads. can anyone help?


It doesn't do anything to the thread that you are trying to join().

Basically, it causes the current thread, to wait until the thread, that you are trying to join with, to exits. When that thread is no longer alive, the join() method will return.

Henry


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

Joined: Apr 30, 2007
Posts: 52
there are two froms of the join method.....................

1) final void join() throws InerruptedException

and
2) final void join(long millisex) throws InerruptedException

a call to both these methods invoed on athread will wait and not reutrn until either the thread has completed or it is timed out after the specificed time, respectively......


that is the first thread waits for the second thread to join in after completeion.
A running thread t1 invokest the method join() on a thread t2.

The join has no effect if threadt2 has already completed. if t2 is alice then t1 transits to the blocked-for-join completion state. the thread t1 waits in this state until one of these occur..........

a) thread t2 completes ------ in this case t1 is enabled and when it gets to run, it will continure normally

b) thread t1 is timed out (time specified int he argument as in (2))

c) thread t1 is interrupted --------- then the InerruptedException will be thrown.........
suresh mulagala
Ranch Hand

Joined: Feb 18, 2003
Posts: 41
Try this..



here th1.join() will make th1 execute completely and finish before th2 starts to execute.
[ October 02, 2007: Message edited by: suresh mulagala ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: join()
 
Similar Threads
URGENT - NEED HELP - Block Code
Can the color for the disabled item be changed
Private methods
error in Marcus Green 2.
WA #1.....word association