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

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

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

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:

Ads