To the original question:
The main
thread calls t.start() once. From that moment on, there are two threads which may be active, and we don't know for sure which will happen first. The main thread may remain active, and call t.start() again, which should result in an
IllegalStateException being thrown. This has no effect on the new thread though, which would then proceed to run. So the output would be:
Exception
Inside Run
Alternately, after t.start() is called the first time, the new thread may run immediately. After it completes, the main thread may resume and call t.start(0 a second time, which will again result in error. The output in this case would be:
Inside Run
Exception
Either of these is possible, and we have no way of knowing which will happen.
[Jay]: This is a bug in j2sdk1.4 and has been fixed in tiger release. Mmm, I think you're thinking of the fact that previous JDKs did not correctly throw IllegalThreadStateException, as documented
here. On older JDKs you might see only
Inside Run
However this was definitely a bug, and has been fixed now. And it wouldn't really account for the output Rathi is asking about.