• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread.join

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the API, "A timeout of 0 means to wait forever."
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is true. Not sure what you mean by "how". What specifically about how it's possible interests you?
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's how. The code for Thread.join(long millis) is as follows:

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic