This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

doubts regarding join from dans mock  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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!!
 
Let nothing stop you! Not even this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!