can we call the run() method instead of start()


Question

can we call the run() method instead of start() to start a thread

Answer

No, you cannot. You need to call start method directly to start a thread. If you call run method directly, it will be executed in the same thread.



Lets understand with the help of example:

Output:

As you can see here even if we have created two threads,everything is getting executed in main thread.

Let’s call start method instead of run method


When you run above program , you will get below output:

As you can notice here, code is executed by two threads in parallel as we have used start method to start the threads here.

Leave a Reply

Your email address will not be published. Required fields are marked *