Threads and lifecycle question 7 of 180 junior
Why must you call start() rather than run()?
run()throwsIllegalThreadStateException- Correct:
run()executes the body on the current thread; onlystart()asks the JVM for a new one - There is no difference,
start()is a convenience method run()starts the thread but without a stack
run() is an ordinary method call. It executes on the calling thread, the new thread is never
created, and everything is sequential. start() registers the thread with the OS scheduler, which
then calls run() on the new stack.
A second detail interviewers like: a Thread object is single use. Calling start() twice throws
IllegalThreadStateException, because the state machine only ever moves forward towards TERMINATED.