• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Understanding Thread join()

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two classes one is main method other is a class which implements runnable interface.

I want to print threads in console of order t3 then t2 and then t.

I read in the internet that the order can be ensured by calling thread.join() inside run but was not able to pass t3 and t2 and t thread objects to the class which implements runnable.

how to pass thread objects to the class and call t3.join and t2.join and t.join inside run method

here are the classes which i have written are






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

https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join%28%29



join only return when the tread is terminated.


view this thread for more complex use cases:
https://coderanch.com/t/656502/java-programmer-SCJP/certification/synchronized-threads#3040568
 
this llama doesn't want your drama, he just wants this tiny ad for his mama
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic