| 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?
|
 |
 |
|
|
subject: 2nd time thread is neither running nor throwing exception, why?
|
|
|