Why do we call the start()
method, which in turn calls the run()
method?
Can't we directly make a call to run()
?
Please give an example where there is a difference.
No, you can't. Calling run will execute run()
method in the same thread, without starting new thread.
Why do we call the
start()
method, which in turn calls therun()
method?
No that's imprecise. start()
in turn does not call the run method. instead it starts the thread which executes the run method. This is native.
Can't we directly make a call to
run()
?
If you call run()
directly you don't start the thread, you just execute the method on the same caller method.
Please give an example where there is a difference.
There are millions on the web. Hence I don't duplicate.
Actually thread.start()
creates a new thread and have its own execution scenario.
but thread.run()
not creating any new thread, instead it execute the run method in the current running thread.
So guys if you are using thread.run()
then think that what is the use of multi-threading if you want only one thread execute all run method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With