• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

how to use join( )

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 .
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
superb logic
thanks a lot .
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic