Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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

doubts regarding join from dans mock

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question from dan's topic wise test

g]Thread.join will return immediately if the timeout value is zero
h] A timeout of zero will allow Thread.join to wait forever if necessary .

According to my understanding g] should be true and h] should be false.But the answer is other way round.
The maximum time limit to wait for the death of the referenced thread can be specified in milliseconds by an argument. Now if time-out is 0 secs then shouldnt g be correct.
Maybe there is something wrong in my understanding..Plz help me clarify this concept.

Anjali
[ October 04, 2005: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you read the API for the Thread join method? If you have not, then I suggest that you do so. If you need help on finding the API or the appropriate part of it please let us know, and we will direct you to it.
 
anjali desh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have gone through it Barry...But will take your suggestion and read it again.Maybe I missed something or mis-interpreted something.
Thanks,
Anjali
[ October 05, 2005: Message edited by: anjali desh ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following is from API

join
public final void join(long millis)
throws InterruptedException
Waits at most millis milliseconds for this thread to die. A timeout of 0 means to wait forever.
 
anjali desh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will time-out of 0 be represented as..
t2.join(0)?
Wont this mean wait atmost 0 seconds? So wont thread t1 return to the runnable state immediately?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, because: A timeout of 0 means to wait forever. join(0) will wait forever, by definition it is an exception to the rule.

Object.wait also waits forever if the argument is 0.

(Sorry Anjali about the emphasis on reading the API. I did it because some posters never do take look at it when they have a doubt.)
 
anjali desh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Barry..This question was troubling me since morning and I was finding it hard to concentrate on other topics..especially as I have got my exam scheduled on saturday and threads is one of the most dreaded topics!!
And you definately dont have to say sorry!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic