What if we call run() method directly instead start() method?

  • Each thread starts in a separate call stack.
  • Invoking the run() method from main thread, the run() method goes onto the current call stack rather than at the beginning of a new call stack.
Test it Now
Output:running...
MainThreadStack Problem if you direct call run() method
Test it Now
Output:1
       2
       3
       4
       5
       1
       2
       3
       4
       5
 
As you can see in the above program that there is no context-switching because here t1 and t2 will be treated as normal object not thread object.
Next TopicJoining A Thread




Contact US

Email:[email protected]

Calling run() method
10/30