| Author |
Doubt regarding start() method of Thread class
|
Mansukhdeep Thind
Ranch Hand
Joined: Jul 27, 2010
Posts: 1142
|
|
Hi
I read that we need to call start() method on a Thread object to make it a thread of execution. How does start() method internally handle the call to run()? Why is the start() method there at all? I mean we could have directly started the thread by saying t.run(). Why a separate method to start() which then calls run()?
|
~ Mansukh
|
 |
Anayonkar Shivalkar
Bartender
Joined: Dec 08, 2010
Posts: 1295
|
|
Well, the simple answer is:
If you call run method, you are just invoking a method on an object within the same thread. No new thread is created.
However, when you call start method, a new system level thread is created, proper context (a separate stack etc.) is set, and that thread is further executed concurrently (here, run method is invoked by thread manager).
|
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD)
|
 |
Mansukhdeep Thind
Ranch Hand
Joined: Jul 27, 2010
Posts: 1142
|
|
|
Thank you.
|
 |
 |
|
|
subject: Doubt regarding start() method of Thread class
|
|
|