Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

star() and run() in Thread

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Khuzema Dharwala
Ranch Hand
Posts: 51
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic