How to start a java thread java interview question and answer
376 views · Published 17 October 2012 · 2:46 · Indexed 1 October 2026
Channel: Interview DOT · 2012 · Science & Technology
Click here - https://www.youtube.com/channel/UCd0U_xlQxdZynq09knDszXA?sub_confirmation=1 to get notifications. http://www.interviewdot.com http://www.interviewdot.com http://www.interviewdot.com
Welcome to www.InterviewDot.com How to prepare for java interview Questions :
How to start a java thread ? Java interview questions and answers
Before starting a thread ,thread object has to be created.
Thread t = new Thread(MyRunnable);
//t refers to thread of execution rather than the thread class. its said to be in NEW state.
So what happens after you call start() method ?
A new thread of execution starts with a new call stack.
The thread moves from the new state to the runnable state.
When the thread gets a chance to execute ,its target "run()" method will run();
Note :
You always start a "Thread" not a runnable. You call start on thread's instance not on runnable instance.
Public class InterviewDotThread {
Public static void main(String[] args){
MyRunnable runnable = new MyRunnable ();
Thread t = new Thread (runnable);
t.start();
}
}
For more Java Interview questions and answers - logon to www.InterviewDot.com - India's Top Interview Guide.
http://www.interviewdot.com http://www.interviewdot.com http://www.interviewdot.com
More from this channel
-
3:19
java interview best books
-
5:51
Top 4 Job Interview Tips How to prepare for Job interview
-
2:42
what are different access modifiers core java interview questions and answers
-
2:08
Interview dos and donts how to prepare for interview
-
0:43
Top Core Java Interview questions and answers 8
-
1:00
Top Core Java Interview questions and answers 2
-
1:04
Top Core Java Interview Question and Answer 9
-
2:56
Tips to find a job interview question and answer