• Post Reply Bookmark Topic Watch Topic
  • New Topic

Could you explain "join()"?  RSS feed

 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks in advance
 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I already checked that link but it did not help much. I confused between currently running thread and t's thread.

Could you please help and explain it to me?

Thanks
 
Henry Wong
author
Sheriff
Posts: 22853
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhimanyu Jain wrote:
I already checked that link but it did not help much. I confused between currently running thread and t's thread.

Could you please help and explain it to me?


The "currently running thread" is the thread that is currently running -- meaning the running thread that called the join() method. Admittedly, the tutorial probably forgot about multi-core environments, where more than one thread can run at the same time, but you can probably figure out that it is the caller thread nonetheless.

The t's thread, is the thread that is represented by the Thread object, that the "t" variable is referring to.

Henry
 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the explanation.
 
Sergei Zhylinski
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you open the source code of the Thread class, you will see that join() uses Thread.isAlive() and Object.wait() methods. See the alternative code below:



And this is all. The main thread puts itself into waiting state and waits for the notification. When the second thread is dead, the main thread will be notified.
 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I already did that, thanks.

Regards
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!