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

  1. Each thread starts in a separate call stack.
  2. 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.

Flash Soon


Output:

Problem if you direct call run() method

Flash Soon


Output:

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.

Copyright 2017 Design& Development