码迷,mamicode.com
首页 > 其他好文 > 详细

Callable 和 Runnable 的区别

时间:2017-04-04 10:33:45      阅读:501      评论:0      收藏:0      [点我收藏+]

标签:runnable   name   exce   sub   except   返回值   exception   submit   service   

Callable 和 Runnable 的使用方法大同小异, 区别在于: 
1.Callable 使用 call() 方法, Runnable 使用 run() 方法 
2.call() 可以返回值, 而 run()方法不能返回。 
3.call() 可以抛出受检查的异常,比如ClassNotFoundException, 而run()不能抛出受检查的异常。 



注意ExecutorService 在Callable中使用的是submit(), 在Runnable中使用的是 execute()

Callable 和 Runnable 的区别

标签:runnable   name   exce   sub   except   返回值   exception   submit   service   

原文地址:http://www.cnblogs.com/zedosu/p/6664384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!