A thread’s run method is invoked by JVM when Thread.start() is called by the programmer.
-
What does the JVM do in background before calling
Thread.run()? -
Why is
Thread.run()not exposed to the user?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It does the JVM work to manage the thread object (allocate stack space, thread-locals, …) and the per-architecture native work of forking and scheduling a new thread/process/clone or whatever the architecture uses to implement threads.
I assume you are talking about “exposed” in terms of the stack frame. Just like the the static
mainmethod, there obviously are call frames above the user code that aren’t exposed to the user because they aren’t useful and would be confusing. I’d say the same thing about theThread.run()method. It will show up in the call stack if you extendThreadand overriderun()but won’t if you are passing in a targetRunnable.I have a lot of details about this in this answer: