Reputation: 2869
I am fairly new to the concept of multithreading and there is an aspect which is not clear to me.
There are two ways to create and run a thread:
start()
the thread. Thread
constructor and start()
the thread. And this blog post states that we always should start a thread using a start()
or so was my impression of it.
But in one of the answers here you could see how a person is using runnable.run()
. It gives me an impression of somewhat wrong practice.
Is it normal? Should it be avoided? You can be explicit in your answer, but any suggestions would be appreciated.
Upvotes: 4
Views: 546
Reputation: 6698
They're just different things. run()
executes the Runnable in the current thread. Calling start()
, on the other hand, causes the Runnable to run in the new thread.
The tutorial points it out as a pitfall. You went through all that trouble to make a thread, so if you go on to run it in the current thread instead, then it's likely a mistake.
Upvotes: 5