简体   繁体   中英

java thread which is better way?

while creating a thread in java, there is two ways such as Extending threads and Implement runnable Interface. I am unaware of Which is the better way of creating threads?

显然,实现Runnable更好,因为它可能允许您使用无法与Thread一起使用的线程池和执行队列,除了显而易见的事实是,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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM