Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners pls tell me the difference between the run() and start() in threads in java....
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kalyanichandra
pls tell me the difference between the run() and start() in threads in java....
1 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners


difference between the run() and start() in threads in java....


Advertisement
View Answers

November 28, 2011 at 12:59 PM


The separate start() and run() methods in the Thread class provide two ways to create threaded programs. The start() method starts the execution of the new thread and calls the run() method. The start() method returns immediately and the new thread normally continues until the run() method returns.

The Thread class' run() method does nothing, so sub-classes should override the method with code to execute in the second thread. If a Thread is instantiated with a Runnable argument, the thread's run() method executes the run() method of the Runnable object in the new thread instead.

Depending on the nature of your threaded program, calling the Thread run() method directly can give the same output as calling via the start() method, but in the latter case the code is actually executed in a new thread.



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com