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 ]
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.