public class ThreadDemo05 {
public static void main(String[] args) throws ExecutionException, InterruptedException {
//使用Runnable创建线程
new Thread(new A(),"aa").start();
//使用Callable创建线程
FutureTask<Integer> vFutureTask = new FutureTask<>(() -> {
System.out.println(Thread.currentThread().getName() +"come in callable");
return 100;
});
new Thread(vFutureTask,"lucy").start();
while (!vFutureTask.isDone()){
System.out.println("wait....");
}
System.out.println(vFutureTask.get());
System.out.println(vFutureTask.get());
System.out.println(Thread.currentThread().getName()+"com over");
}
}
class A implements Runnable{
@Override
public void run() {
}
}
class B implements Callable{
@Override
public Object call() throws Exception {
return 100;
}
}