1 Answers
Differences between Thread.start() and Thread.run() in Java
When working with multithreading in Java, it is important to understand the differences between Thread.start()
and Thread.run()
methods:
- Thread.start(): This method is used to start a new thread of execution. When
Thread.start()
is called, a new thread is created and therun()
method is executed in that new thread. - Thread.run(): This method is just a normal method of the Thread class. When
Thread.run()
is called directly, it does not create a new thread and therun()
method is executed in the current thread of execution, just like any other method call.
It is important to note that using Thread.run()
directly does not provide the benefits of multithreading, as the code will run in the same thread as the caller. To achieve parallel execution and leverage the benefits of multithreading, Thread.start()
should be used to start a new thread.
Please login or Register to submit your answer