aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 2nd time thread is neither running nor throwing exception, why? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "2nd time thread is neither running nor throwing exception, why?" Watch "2nd time thread is neither running nor throwing exception, why?" New topic
Author

2nd time thread is neither running nor throwing exception, why?

yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257

above script is printing only one "hello". second start() is not printing hello why?
I thought calling same thread twice cause IllegalThreadState exception. but it is not giving exception also.
(code tags added - use edit button to see how to do it)
[ April 28, 2004: Message edited by: Barry Gaunt ]
Sekhar Kadiyala
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
If you comment the join part of code, it is going to throw the error that you are expecting. But i am also surprised what difference join is making it ignore the second 'start'


PMP CSQA SCJP SCWCD SCBCD INS 21 INS 23
Karel KoboojBot
Ranch Hand

Joined: Apr 09, 2004
Posts: 35
Deleted by request (next down).
Next time use the EDIT thingie (paper/pencil icon)
[ April 28, 2004: Message edited by: Barry Gaunt ]
Karel KoboojBot
Ranch Hand

Joined: Apr 09, 2004
Posts: 35
First of all, sorry about reply above (had a slight problem with my tab key ). Could one of the administrators delete this please ?

This code will print "hello" during the run of the thread because of the first start() invocation.
The second time you call start() on this thread, that thread will already be dead because you have a join in your code. The implementation of JVM 1.4 allows you to do this, but it will not run the thread again, because a dead thread stays dead. Hence, no second printing of "hello".
Now the strange part. Even though the JVM 1.4 implementation does not throw an exception (you would expect a IllegalThreadStateException), if you get a question on the exam about it, you should say that it does throw one (because it says so in the official API).
Hope this helps.
Sekhar Kadiyala
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
Isn't it some sort of bug?
Bert/Kathy, Do you guys have any idea?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2nd time thread is neither running nor throwing exception, why?
 
Similar Threads
Threading question
Thread - join()
Threads trying to get InterruptedException
What is the output of the program?please explain....
Thread Question