Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt regarding start() method of Thread class

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()?
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic