aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread once again (Join) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread once again (Join)" Watch "Thread once again (Join)" New topic

Thread once again (Join)

Ramnath krishnamurthi
Ranch Hand

Joined: Jan 22, 2003
Posts: 56
I was looking at the Thread api and one of the interesting thing i have noted in join(long millisecs) method is that ,A time out of 0 means to wait forever.
I tried to test this fact using 2 scenarios and as usual i became confused.
Scenario 1:

The output is :
Am going to sleep
I woke up
I am main
Scenario 2:

The output is :
Am going to sleep
I woke up
I am main
My confusion here is:
should not that t.join(0) in the Scenario 2 makes the main thread to wait for ever and not printing the I am main at all?.
Thanks in advance for any help.
Feed an Opportunity.Starve a Problem

Modified title to be more informative, removed loud bangs, and added code tags...
[ April 10, 2004: Message edited by: Barry Gaunt ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
The join(0) with 0 as an argument is the same as join() with no argument. The main thread will wait forever if the started thread does not complete. But the started thread does complete.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
It is sorta covered in the JavaRanch Style Guide.
subject: Thread once again (Join)