This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread.join

 
Vishal Arora
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please let me know whethere it is tru or not:
A timeout of of zero will allow Thread.join to wait forever if necessary.

If it is true then how.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the API, "A timeout of 0 means to wait forever."
 
Sergei Iakhnin
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is true. Not sure what you mean by "how". What specifically about how it's possible interests you?
 
Joe Sondow
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's how. The code for Thread.join(long millis) is as follows:

 
shyam ramineni
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

From the code I understand that if we call t2.join(0) in thread t1, then, t1 will wait forever till t2 completes.
t1 will start if thread t2 has finished.

am I right.

Shyam Ramineni
 
Joe Sondow
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shyam ramineni:
Hi All,

From the code I understand that if we call t2.join(0) in thread t1, then, t1 will wait forever till t2 completes.
t1 will start if thread t2 has finished.

am I right.

Shyam Ramineni


Almost right. Your first sentence is correct. t1 will wait, potentially forever, until t2 completes. Your second sentence is not quite right, but it's close. t1 won't necessarily start up again if t2 has finished, but t1 will become runnable when t2 finishes, so the thread scheduler can then resume the execution of t1 when the scheduler chooses to do so.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic