java thread which is better way?
while creating a thread in jav开发者_开发百科a, there is two ways such as Extending threads and Implement runnable Interface. I am unaware of Which is the better way of creating threads?
Obvously, implementing Runnable is by far better since it potentially allow you to use thread pools and execution queue that you couldn't use with Thread, besides the obvious fact your thread number is limited in the JVM.
Implementing the interface is considered better, but not because of anything specific to threads. In general implementing an interface gives your code more flexibility because you can implement multiple interfaces but only extend a single class. Suppose you wanted to extend another super class and create a thread at the same time?
Implementing Runnable is better. Josh Bloch covered it in correspondent chapter of Effective Java.
精彩评论