Two Laptop Bag*
The moose likes Beginning Java and the fly likes Doubt regarding start() method of Thread class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt regarding start() method of Thread class" Watch "Doubt regarding start() method of Thread class" New topic
Author

Doubt regarding start() method of Thread class

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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: 1509
    
    5

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, OCEEJBD)
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Thank you.
 
GeeCON Prague 2014
 
subject: Doubt regarding start() method of Thread class