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

Calling Thread By Start() and Run()

 
RAGU KANNAN
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

what is the differnet between calling a Thread by start() and run().

Thanks, Raghu.K

public static void main(String[] args) {
MyThread a = new MyThread("A");
MyThread b = new MyThread("B");
b.start();
a.run();
}
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The start method will create a seperate thread of execution. When you invoke the run method, its not a seperate thread. This program has two threads running. They are main and thread b. a.run() will not start a thread. The run method is mounted on main's call stack.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic