Best way to create a thread | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Best way to create a thread

what is the best way to create a thread- by implementing Runnable or by extending Thread? and why?

7th Oct 2017, 1:48 PM
Adarsh Srivastava
Adarsh Srivastava - avatar
2 Answers
+ 4
I prefer to implement Runnable and to be able to extends to other classes
7th Oct 2017, 5:30 PM
Edward Fish
Edward Fish - avatar
0
There are no rules about which of the two methods that is best. Both are best. Personally though, I prefer implementing Runnable, and hadling en instance of the implementation to a Thread instance. When having the Runnable's executed by a thread pool it is easy to queue up the Runnable instances until a thread from the pool is idle. This is little harder to do with Thread sub classes.
8th Oct 2017, 8:56 AM
Adarsh Srivastava
Adarsh Srivastava - avatar