This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread once again (Join)" Watch "Thread once again (Join)" New topic
Author

Thread once again (Join)

Ramnath krishnamurthi
Ranch Hand

Joined: Jan 22, 2003
Posts: 56
Hi,
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.
Ramnath
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Thread once again (Join)
 
Similar Threads
this and static method
Question on Thread
Doubt in Thread
Threads
static inner class