• Post Reply Bookmark Topic Watch Topic
  • New Topic

Understanding Thread join()  RSS feed

 
amithk kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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






 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • 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:
http://www.coderanch.com/t/656502/java-programmer-SCJP/certification/synchronized-threads#3040568
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!