Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads: differnece between start() and run()

 
sameer inamdar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • 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.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • 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.
 
Wensheng Li
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic