Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't we directly call the run() method?

If the start() method of a thread internally calls the run() method, then why don't we directly call the run() method in our code? What are the issues involved in doing so?

like image 642
n_g Avatar asked Jan 28 '11 16:01

n_g


1 Answers

The start method makes sure the code runs in a new thread context. If you called run directly, then it would be like an ordinary method call and it would run in the context of the current thread instead of the new one. The start method contains the special code to trigger the new thread; run obviously doesn't have that ability because you didn't include it when you wrote the run method.

like image 186
Rob Kennedy Avatar answered Oct 29 '22 22:10

Rob Kennedy