首页 > 编程知识 正文

android应用程序开发第三版,多线程实现runnable

时间:2023-05-03 12:33:56 阅读:154916 作者:1410

我还很肤浅,如果有错误的话请谅解

Runnable接口的说明

官方地址是以下:

官方解释如下

therunnableinterfaceshouldbeimplementedbyanyclasswhoseinstancesareintendedtobeexecutedbyathread.theclasstdefineamethodofneth

thisinterfaceisdesignedtoprovideacommonprotocolforobjectsthatwishtoexecutecodewhiletheyareactive.for example, runnableisimplementedbyclassthread.beingactivesimplymeansthatathreadhasbeenstartedandhasnotyetbeenstopped。

在编辑中, runnableprovidesthemeansforaclasstobeactivewhilenotsubclassingthread.aclassthatimplementsrunablecanrunwithoutsubclassingthread nnablecanrunwithoutsubcl byinstantiatingathreadinstanceandpassingitselfinasthetarget.in most cases、 therunnableinterfaceshouldbeusedifyouareonlyplanningtooverridetherun

慢慢翻译

这个Runnable接口应该在有意识地实现单线程的例子中被继承

在本例中,需要定义没有参数的方法run

此接口旨在为对象提供用于执行活动代码的常规协议。 很抱歉我不能理解这句话是什么意思。 举个例子,Thread继承了Runnable,然后Thread是一个活的单线程示例。

此外,Runnable还为一个类提供了一种成为活动进程的方法。 而且没有对Thread进行子类化。 一个类继承了Runnable可执行且未子类化。 Thread就是一个例子

将实例本身作为目标传递。 大多数股都应该使用Runnable接口。 run ) )如果只重写方法而不写Thread方法,这一点很重要,因为不应该将类子类化。 除非这个项目打算修饰或强化基本原则来表达这个类。

以下是关于run方法的翻译

公共备用语音运行(

whenanobjectimplementinginterfacerunnableisusedtocreateathread,startingthethreadcausestheobject ' srunmethodtobecalledinthat

thegeneralcontractofthemethodrunisthatitmaytakeanyactionwhatsoever。

翻译:

当类实现Runnable接口时,必须重写Run方法。

Run方法是用于在独立的单线程内生成的方法。

方法执行的一般约定是它可以采取什么样的操作。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。