package com.taku.complate_future;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class CombindStudentInfo {
static UserService service = new UserService();
private static String name = "taku";
private static String location = "北京四合院";
public static void main(String[] args) throws Exception {
//long l = System.nanoTime();
//StudentInfo studentInfo = AsyncGet(name, location);
//long end = System.nanoTime();
//System.out.println(end - l);
//System.out.println(studentInfo);
composeTest();
}
static StudentInfo syncGet(String name,String location){
StudentInfo studentInfo = new StudentInfo();
// 获取name ,age
Student student = service.getStudent(name);
studentInfo.setAge(student.getAge());
studentInfo.setName(student.getName())
CompleteFuture使用demo
最新推荐文章于 2024-06-26 09:42:02 发布
本文详细介绍了Java的CompletableFuture类,它用于处理异步计算。通过实例代码演示了如何创建、组合CompletableFuture,以及如何优雅地处理结果和异常,为并发编程提供了强大的工具。
摘要由CSDN通过智能技术生成