1.创建线程池
ExecutorService executorService = Executors.newFixedThreadPool(10);
2.创建线程Callable
Callable<T> callable = new Callable<T>() {
@Override
public Boolean call() throws Exception {
//业务逻辑
}
};
3.将Callable写的任务封装到一个由执行者调度的FutureTask对象
FutureTask<T> futureTask = new FutureTask<T>(callable);
4.执行
executorService.execute(futureTask);
5.获取反参
Object obj = futureTask.get();
附加:可同时创建多个Callable并发执行