使用Runnable模拟Callable接口实现线程有返回值

上传者: cheng_zhen | 上传时间: 2021-04-05 15:54:54 | 文件大小: 9KB | 文件类型: RAR
大家都知道Runnable和Callable接口都可以作为其他线程执行的任务,但是Runnable接口的run方法没有返回值,而Callable接口的call方法有返回值,那么Callable接口是如何做到的呢?在此我给出一个Demo,看看通过Runnable接口如何实现Callable接口的有返回值。这个例子并不摘自JDK中Callable接口源码,只是提供一种可行方案,仅供参考!该Demo解压、导入到开发环境即可,测试入口为test包下的MainTest.java

文件下载

资源详情

[{"title":"( 16 个子文件 9KB ) 使用Runnable模拟Callable接口实现线程有返回值","children":[{"title":"Runnable_Callable","children":[{"title":".project <span style='color:#111;'> 393B </span>","children":null,"spread":false},{"title":"src","children":[{"title":"com","children":[{"title":"huaxia","children":[{"title":"my","children":[{"title":"concurrent","children":[{"title":"callable","children":[{"title":"FutureTask.java <span style='color:#111;'> 790B </span>","children":null,"spread":false},{"title":"test","children":[{"title":"MyCallableClass.java <span style='color:#111;'> 389B </span>","children":null,"spread":false},{"title":"MainTest.java <span style='color:#111;'> 644B </span>","children":null,"spread":false}],"spread":true},{"title":"Future.java <span style='color:#111;'> 170B </span>","children":null,"spread":false},{"title":"ExecutorService.java <span style='color:#111;'> 824B </span>","children":null,"spread":false},{"title":"Callable.java <span style='color:#111;'> 210B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":".settings","children":[{"title":"org.eclipse.jdt.core.prefs <span style='color:#111;'> 629B </span>","children":null,"spread":false}],"spread":true},{"title":".classpath <span style='color:#111;'> 301B </span>","children":null,"spread":false},{"title":"bin","children":[{"title":"com","children":[{"title":"huaxia","children":[{"title":"my","children":[{"title":"concurrent","children":[{"title":"callable","children":[{"title":"Future.class <span style='color:#111;'> 243B </span>","children":null,"spread":false},{"title":"ExecutorService.class <span style='color:#111;'> 1.96KB </span>","children":null,"spread":false},{"title":"Callable.class <span style='color:#111;'> 296B </span>","children":null,"spread":false},{"title":"test","children":[{"title":"MainTest.class <span style='color:#111;'> 1.58KB </span>","children":null,"spread":false},{"title":"MyCallableClass.class <span style='color:#111;'> 1.21KB </span>","children":null,"spread":false}],"spread":false},{"title":"ExecutorService$1.class <span style='color:#111;'> 1.57KB </span>","children":null,"spread":false},{"title":"FutureTask.class <span style='color:#111;'> 1.20KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}]

评论信息

  • liujun3496 :
    东西不错,非常好,谢谢。
    2017-09-17
  • haiguizuotushiyan :
    很值得借鉴学习,又一次加深了对线程的理解
    2014-05-13
  • shuangyidehudie :
    能用,谢谢,给的例子满好用的
    2013-09-13
  • yexuanpk :
    内容比较全面,可以作参考!学习了
    2013-08-20
  • simpletuo :
    不是想象的那样,但是还是可以用的
    2013-05-21
  • venuser :
    内容比较全面,可以作参考!
    2013-05-10

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明