Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread join method?  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S.V.M{
Thread t=new Thread();
t.join;

please correct me if Iam wrong....It Means join Main behind tread t1...right???

and can we join any other thread behind t1...for say t2....and how???
 
Java Cowboy
Sheriff
Posts: 16083
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the API documentation for Thread.join()?

t.join(); means that the thread that you are making this call from (the main thread, for example) waits for thread t to stop.
 
Ranch Hand
Posts: 80
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
t.join() will run thread t and put all other threads in wait after it finishes the process the other threads can now run. InterruptedException is the exception which is thrown if thread t is interrupted by any other threads.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shahir Deo wrote:t.join() will run thread t and put all other threads in wait after it finishes the process the other threads can now run. InterruptedException is the exception which is thrown if thread t is interrupted by any other threads.



I think, the description provided you is confusing and incorrect.

Due to statement t.join(), the main thread will wait till thread t completes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!