文章目录
  1. 1. 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 run() {
}
};
new Callable<String>() {
@Override
public String call() throws Exception {
// TODO Auto-generated method stub
return null;
}
};
  • Runnable 自JDK 1.0就有;Callable JDK 5.0

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

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

  • Callable 泛型接口;

  • Callable 可抛检查型异常;

文章目录
  1. 1. Callable vs Runnable interface in Java