Forums Register Login

Reasoning question on Thread

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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.
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 693 times.
Similar Threads
overriding and polymorphism
Regarding Synchronized
C++'s out parameter object creation and JNA
wait() releases all locks?
method question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:38:33.