• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Threads: differnece between start() and run()

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please share your understanding about the start and run method in a Thread
Thread t
t.start()or t.run()
Its basic that we can call direct run() method of the runnable interface
and call start method of the Thread class.
But I want to know wether there is specific rule for them or they are same.
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the start() method , creates a new call stack and put this thread in new state. But the run() methods has the job or the stuffs needs to be executed in a seperate thread. This method doesnt create a new thread. When a thread goes to running state then it executes the statements in the run method.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, basically calling start() method will create a separate new thread in your program then this new thread will run the codes specified by run().

Calling run() will of course also causes the codes in run() to be run but in the current thread(for example, the main program). No new thread will be created.
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic