Junior — Middle
How does the call to the run method differ from the start method in Java threads?.
sobes.tech AI
Answer from AI
The start() method of a thread in Java launches a new execution thread and calls the run() method in this new thread. That is, when you call start(), a separate thread is created, and the code inside run() executes in parallel with the main thread.
If you call the run() method directly, it will execute in the current (main) thread without creating a new one.
Example:
Thread thread = new Thread(() -> System.out.println("Running in a new thread"));
thread.start(); // Launches a new thread
thread.run(); // Executes in the current thread, like a normal method