aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to use 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 "how to use join( )" Watch "how to use join( )" New topic
Author

how to use join( )

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830


In this program , I want to join t2 thread ( fast one ) into t1 or in other word I want that t1 should finish first & then t2 .

how can I do this ?

thanks .
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Do you want t2 to join t1 or do you want the application to join t1 before it even starts t2?

If the former you need to have a reference to t1 inside t2 and call join in t2.
If the latter, you call t1.join(); before you call t2.start();


42
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Jeroen Wenting:
Do you want t2 to join t1 or do you want the application to join t1 before it even starts t2?

If the former you need to have a reference to t1 inside t2 and call join in t2.
If the latter, you call t1.join(); before you call t2.start();


application means main thread , right . so yes I can join it like t1.join() after t1.start() , that is solving my purpose ... because now t2 will start execution after t1 will get completed .


Jeroen , can you explain first one with some code .. please
thanks a lot .
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Sure.
You'll need to either modify your Runnable a bit first though.



Now t2 will wait until t1 is done. t1 will wait for nothing because its waitFor Thread is null.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
superb logic
thanks a lot .
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi jaroen ,

Can you please extends this code to use wait() , notify() & notifyAll() mrthod & explain ... please .

thanks a lot .
 
Don't get me started about those stupid light bulbs.
 
subject: how to use join( )