java - 如何创建 org.springframework.util.concurrent.ListenableFuture 的完整实例

标签 java spring

如何创建org.springframework.util.concurrent.ListenableFuture的虚拟实例?

它应该代表具有给定结果的已完成任务。

最佳答案

假设字符串结果,您可以使用以下内容:

    String result = "result";
    ListenableFuture<String> future = new AsyncResult<>(result);
    String dummy = future.get();

但是,如果需要,任何对象都可以包装在AsyncResult中。

关于java - 如何创建 org.springframework.util.concurrent.ListenableFuture 的完整实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54590721/

相关文章:

xml - hibernate注释类的通用定义

java - 首次登录时无法打开 Hibernate Session 进行事务处理

java - Sftp 出站网关多个删除请求在第一个 "File not found"问题后卡住

java - SQLite删除列: Using temporary table vs Renaming using ALTER TABLE的方法

java - PlantUML - 如何将私有(private)方法表示为序列图中的嵌套生命线

java - 通过 TCP 发送两种不同类型的数组

java - 程序在 ObjectInputStream 阻塞

Java 正则表达式 : word ending in 's' except specific words

java - 使用 RestTemplate 和 RestTemplateCustomizer 与多个服务的正确架构是什么?

java - 数据未存储在数据库中