Java中Runnable和Callable接口的区别 [英] The difference between the Runnable and Callable interfaces in Java

查看:39
本文介绍了Java中Runnable和Callable接口的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 中设计并发线程时,使用 RunnableCallable 接口有什么区别,为什么要选择一个?

What is the difference between using the Runnable and Callable interfaces when designing a concurrent thread in Java, why would you choose one over the other?

推荐答案

查看说明 这里.

Callable 接口类似于可运行,因为两者都是设计的对于实例为可能被另一个人执行线.然而,Runnable 不会返回一个结果并且不能抛出一个检查异常.

The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.

这篇关于Java中Runnable和Callable接口的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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