What happens if you call run() instead of start() on a Java thread?
start() creates a new thread of execution and calls run() on it. Calling run() directly is an ordinary method call on the current thread, so no concurrency happens. Calling start() twice throws IllegalThreadStateException.
Explain it simply
start() is hiring a new worker and giving them a task. run() is you doing the task yourself, while pretending you hired someone.
Example
Thread t = new Thread(() ->
System.out.println("running in " + Thread.currentThread().getName()), "T1");
t.run(); // prints: running in main (same thread, no new thread)
t.start(); // prints: running in T1 (a real new thread)
// t.start(); again -> IllegalThreadStateExceptionWhat to say in the interview
"start() asks the JVM to allocate a new call stack and schedule the thread, and the JVM then calls run() there. A direct run() call just executes the body on the caller's thread, so the code runs sequentially and blocks the caller. A thread object can be started only once; a second start() throws IllegalThreadStateException, even after the thread has finished."
Common mistakes
- Calling run() in a test and concluding that the program is multithreaded.
- Trying to restart a finished thread instead of creating a new one.