Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

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

  • Each thread starts in a separate call stack.
  • Invoking the run() method from the main thread, the run() method goes onto the current call stack rather than at the beginning of a new call stack.

FileName: TestCallRun1.java

Test it Now

Output:

running...

MainThreadStack

Problem if you direct call run() method

FileName: TestCallRun2.java

Test it Now

Output:

1
2
3
4
1
2
3
4

As we 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 TopicJava join() Method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA