• Post Reply Bookmark Topic Watch Topic
  • New Topic

What happens when a running thread calls join?  RSS feed

 
Mahanth Kumar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I read that when a thread calls join, it makes the currently running thread join after it. Please correct me if i am wrong here.

Now what happens if innocently the thread that is currently running calls join()?

I believe the scenario would roughly translate to "Thread.currentThread().join();"

I tried this in eclipse out of curiosity and it seems to me like the VM hung or something. There was a process running but i couldnt see anything on the console

If this is the case wouldnt it lead to catastrophic results in case in an application only one thread happens to be running at some point and it calls join()


Cheers
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahanth Kumar wrote:
If this is the case wouldnt it lead to catastrophic results in case in an application only one thread happens to be running at some point and it calls join()


Yea... I guess. But wouldn't it also be "catastrophic". if you call the System.exit() method when you didn't mean to? Having a thread wait for itself to finish, is simply a bug, and it is probably as bad as any other bug.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!