This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Diffrence  between calling the run() method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Diffrence  between calling the run() method." Watch "Diffrence  between calling the run() method." New topic
Author

Diffrence between calling the run() method.

Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133
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

Joined: Aug 05, 2005
Posts: 3742
    
  16
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.


Joanne
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Actually, calling start does not create a new Thread, but it does create a new thread.

Remember that Java is case-sensitive.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20083
    
  30

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Diffrence between calling the run() method.
 
It's not a secret anymore!