• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

start() method of the Thread class

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

My doubt is about the start() method of the thread class.

why it is compulsory that to start a thread we need to call start() method
?is it not possible to directly call the run() method to run the Thread?

what is the difference between this to approaches???
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can call run if you like but you'll be running in the same thread (you code flow won't continue until run completes as everything is sequential) , i.e. your application won't be multithreaded , if you call start that will result in run being called but this time in another thread, i.e. your code won't wait for run to complete , run can 'run' in parallel to your current code execution.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each thread has its very own stack of execution.In case you are calling run directly , you will not create any thread , rather you will run method run in the same thread's stack.No new stack created , hence no new thread.
 
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would also like to add one more point here..
start() method is a native method of class Thread..
which by its implementation, creates a new thread
and calls run() method of class Thread..

However, in case of being overridden,
at runtime, by virtual method invocation,
overridden version of run() method is invoked..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic