Forums Register Login

star() and run() in Thread

+Pie Number of slices to send: Send
When a Thread class is extended to create a thread, run() of Thread class is overridden. Does it mean that I don't need to use start() to start the thread and I can directly execute run() to start new thread ? OR do I still need to execute start() of Thread class, which in turn will execute run() of Thread class ?

Does it mean that no matter what, to start second stack for thread, its required to execute start(). If I execute run() without start(), then this run() will go on the same stack where main() is executed ?

Is start() only way to start a new stack or is there any other way also ?

Thanks
+Pie Number of slices to send: Send
call to start() is required to create a separate thread of execution irrespective of whether you are extending a Thread class or implementing Runnable interface

you can test this scenario by calling static activeCount() method of Thread class which will return active threads in the current thread's thread group.

Thanks....
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 728 times.
Similar Threads
Threads: differnece between start() and run()
Thread Question
Threads...
difference between start() and run() of a thread instance
join()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:52:58.