This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubts regarding join from dans mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubts regarding join from dans mock" Watch "doubts regarding join from dans mock" New topic
Author

doubts regarding join from dans mock

anjali desh
Ranch Hand

Joined: Aug 04, 2005
Posts: 32
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 ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
anjali desh
Ranch Hand

Joined: Aug 04, 2005
Posts: 32
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 ]
Roja Rani
Greenhorn

Joined: Sep 28, 2005
Posts: 22
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

Joined: Aug 04, 2005
Posts: 32
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

Joined: Aug 03, 2002
Posts: 7729
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

Joined: Aug 04, 2005
Posts: 32
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!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubts regarding join from dans mock
 
Similar Threads
Please Help Me...For Above Question
Thread.join
Doubt with join() method
Threads
Problem with Devakas Final Exam Q on Static Thread methods