• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reasoning question on Thread

 
shailesh jamloki
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a very general question about Thread class method.

In any class if we have a method foo() then we call it using foo().

then why do we call run() using start() in the case of Threads?

I guess to show a different process started running?

any concrete answers?

Regards
Shailesh
 
shailesh jamloki
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I got the answer:-

It is possible to call the run() method as run(). but It really do not start a separate call stack.

to call run() with start() is a mechanism to start it in a different mechanism.

But Is this really a reason?
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shailesh jamloki wrote:It is possible to call the run() method as run(). but It really do not start a separate call stack.

Correct. When you call run() it executes that method in the same thread you are calling it from. start() creates a new thread (lowercase to not confuse it as an instance of class Thread) and will then call run() inside that new thread.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic