本文提供异步线程获取返回值的方法 使用 Future
1.返回值为Future<Object>
@Override
@Async()
public Future<List<TMaterialVo>> list(TMaterial tMaterial) {
List<TMaterialVo> list = tMaterialMapper.list(tMaterial);
System.out.println("1---------------");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return new AsyncResult<>(list);
}
2.接收
Future<List<TMaterialVo>> future = asyncService.list(tMaterial).get();