Why we need to pass the runnable instance while creating the threads using the Runnable interface?
Why we need to pass the runnable instance while creating the threads using the
Share
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.
The reason we need to pass the runnable object to the thread object’s constructor is that the thread must have some way to get to the
run()method we want the thread to execute.Take an e.g
Since we are no longer
overriding the
run()method of the Thread class, the defaultrun()method of the Thread class isexecuted; this default
run()method looks like thisHence,
otis the runnable object we passed to the thread’s constructor. So the thread begins execution with therun()method of the Thread class, which immediately calls therun()method of our runnable object.