Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diffrence between calling the run() method.

 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

If you extend any thread class , we should override the run method.

We can call that run method by using obj.start() or obj.run().

Just i want to know difference between them .

Is that start() method will create new Thread () ?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. If you call the run method directly then it will be executed by the current thread. By calling start, a new thread is created and run is executed by that thread.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, calling start does not create a new Thread, but it does create a new thread.

Remember that Java is case-sensitive.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As said before, the difference is that start() will execute the run() method on a new thread, and run() will execute on the current thread.

This is a real stinker in examination; run() is called but the question lets you think that start() is called instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic