wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Reasoning question on Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reasoning question on Thread" Watch "Reasoning question on Thread" New topic
Author

Reasoning question on Thread

shailesh jamloki
Ranch Hand

Joined: Oct 28, 2004
Posts: 38
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

Joined: Oct 28, 2004
Posts: 38
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

Joined: Oct 27, 2005
Posts: 19760
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reasoning question on Thread