哪个方法在线程中更好? [英] which method is better in thread ?

查看:63
本文介绍了哪个方法在线程中更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







你能告诉我哪种方法在线程(java)中更好。例子

1)实现线程

2)类线程线程。





和为什么请解释?

Hi ,


can you please tell me which method is better in thread (java ). example
1) implement thread
2) class thread thread .

?
and why please explain?

推荐答案

http://docs.oracle.com/javase/tutorial/essential/concurrency/index.html [ ^ ]。


嗨Ravi,



在可能的情况下,我使用通常实现接口而不是扩展到线程。为什么?因为如果你实现了接口,你就可以在你的类中实现其他接口,并且将你的类扩展到另一个接口



如果你将类扩展到线程类,你没有把我们的类扩展到另一个类的可能性,这比扩展到线程更有意义。



看看这个论坛:

http://stackoverflow.com/questions/541487/ implements-runnable-vs-extends-thread [ ^ ]



祝你好运

Filipe
Hi Ravi,

In may case, I use normally implements the interface instead extends to thread. Why? Because if you implements the interface, you have the possibility to implements others interfaces in your class and extend your class to another one .

If you extend your class to thread class, you loose the possibility to extend our class to another class, that makes more sense than extend to thread.

Take a look on this forum:
http://stackoverflow.com/questions/541487/implements-runnable-vs-extends-thread[^]

Best regards
Filipe


这篇关于哪个方法在线程中更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆