This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: 2409
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
Sheriff

Joined: Oct 14, 2005
Posts: 19757
    
  10

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
 
It's not a secret anymore!