callable vs runnable interface in java

文章目录

Callable vs Runnable interface in Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
new Runnable() {
public void () {
}
};
new Callable<String>() {
public String call() throws Exception {
return null;
}
};
  • Runnable 自JDK 1.0就有;Callable JDK 5.0

  • Runnable 定义任务方法是 public void run();Callable 定义任务方法是 public call() throws Exception

  • run()无返回值;call返回值;

  • Callable 泛型接口;

  • Callable 可抛检查型异常;