my dog learned polymorphism*
The moose likes Beginning Java and the fly likes start() in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "start() in java" Watch "start() in java" New topic
Author

start() in java

Sanath Ramesh kumar
Greenhorn

Joined: Mar 13, 2012
Posts: 4
Why does the start() automatically call the run()??What happens if the developer explicitly calls run() and also please explain the difference between above two scenarios??
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Calling run directly will execute that method in the current thread. Only by calling start will a new thread be created for the run method to execute in.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Sanath Ramesh kumar wrote:Why does the start() automatically call the run()??


Because the code for start() calls the native method start0(), which has code that says, "Start a new thread of execution, and in it, call this object's run() method."

In other words, it's because that's how the code is written, just like any other time one method calls another.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

To those beginners who don't know what this post was about: It was about the start() and run() methods of the Thread class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: start() in java
 
Similar Threads
Open tomcat server in the same dos window.
General threading problem
Regarding the IllegalThreadStateException
Thread
Thread