哪个方法在线程中更好?

编程入门 行业动态 更新时间:2024-10-27 04:38:06
本文介绍了哪个方法在线程中更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你能告诉我哪种方法在线程(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?

推荐答案

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

嗨Ravi, 在可能的情况下,我使用通常实现接口而不是扩展到线程。为什么?因为如果你实现了接口,你就可以在你的类中实现其他接口,并且将你的类扩展到另一个接口。 如果你将类扩展到线程类,你没有把我们的类扩展到另一个类的可能性,这比扩展到线程更有意义。 看看这个论坛: stackoverflow/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: stackoverflow/questions/541487/implements-runnable-vs-extends-thread[^] Best regards Filipe

更多推荐

哪个方法在线程中更好?

本文发布于:2023-11-14 04:58:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!