摘要
实例代码
package com.zhuangxiaoyan.jdk.juc.JucLock;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
/**
* @Classname CallableDemo
* @Description TODO
* @Date 2021/11/27 15:57
* @Created by xjl
*/
class MyThread implements Runnable {
@Override
public void run() {
}
}
class MyThread2 implements Callable {
@Override
public Integer call() throws Exception {
System.out.println("********************** come in Callable");
return 1024;
}
}
public class CallableDemo {
public static void main(String[] args) throws ExecutionException, InterruptedException {
FutureTask futureTask = new FutureTask(new MyThread2());
Thread t1 = new Thread(futureTask, "AAA");
t1.start();
Integer res = futureTask.get();
System.out.println(res);
}
}