wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Calling Thread By Start() and Run() 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Calling Thread By Start() and Run()" Watch "Calling Thread By Start() and Run()" New topic
Author

Calling Thread By Start() and Run()

RAGU KANNAN
Ranch Hand

Joined: Dec 16, 2005
Posts: 103
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

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling Thread By Start() and Run()
 
Similar Threads
A question about thread
Thread Question
Thread Question---start()
Threads
why run() method in Runnable interface is not called ?