-
14 votesanswersviews
如何取消Java 8可完成的未来?
我正在玩Java 8可完成的期货 . 我有以下代码: CountDownLatch waitLatch = new CountDownLatch(1); CompletableFuture<?> future = CompletableFuture.runAsync(() -> { try { System.out.println("Wait&... -
1 votesanswersviews
如何用Spring处理CompletionStage?
如何配置spring以使用 CompletionStage 返回类型?考虑一下代码: @RequestMapping(path = "/", params = "p", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public CompletionStage<List<My... -
0 votesanswersviews
什么是默认此Collectors.toList以期望一个对象列表?
我们正在使用Java中的@Async注释和CompletableFutures来调用一些调用 . 我们有很多Pojo,我们正在异步调用中创建对象,但是在尝试将结果收集到List时,Eclipse希望我将Pojo列表更改为对象列表,而我不是了解它是否是从流中默认响应的CompletableFuture . List<Pojo1> crudResponse = null; List<... -
53 votesanswersviews
列出<Future>到Future <List>序列
我想将 List<CompletableFuture<X>> 转换为 CompletableFuture<List<T>> . 这非常有用,因为当您有许多异步任务并且需要获得所有异步任务的结果时 . 如果其中任何一个失败,则最终的未来将失败 . 这就是我实施的方式: public static <T> CompletableFuture... -
1 votesanswersviews
在supplyAsync阻塞主线程之后使用thenAccept
我正在开发一个与其他Web应用程序通信的Web应用程序 . 我的系统有时会将HTTP请求作为通知发送给其他系统 . 由于他们的回复对我来说不是必不可少的,我使用Java 8 CompletableFuture supplyAsync发送请求并使用thenAccept打印他们的响应,这样我的主线程就不会被阻止 . 但是,我发现CompletableFuture函数链每次花费大约100到200毫秒,这... -
6 votesanswersviews
在期货清单上流式传输的最有效方式
我通过流式传输对象列表来调用异步客户端方法 . 该方法返回Future . 迭代调用后返回的Futures列表的最佳方法是什么(以便处理那些首先出现的Future)? 注意:异步客户端仅返回Future not CompletableFuture . 以下是代码: List<Future<Object>> listOfFuture = objectsToProcess.pa... -
4 votesanswersviews
Java 8可完善的未来
我的问题是如何使用Completable Future . 我有一个实现Callable的类 . public class Executor implements Callable<Collection> 早先用来做 - service.submit(collectorService); 哪个会返回 Future<Collection> . 但是我们不想再使用未来,需... -
2 votesanswersviews
将可完成的futeres列表转换为列表的一个可完成的未来
我有一个 CompletableFuture 实例列表 . List<CompletableFuture<String>> listOfFutures; 如何将它们转换为这样的未来: CompletableFuture<List<String>> futureOfList = convert(listOfFutures); -
2 votesanswersviews
使用Optional对象返回可完成的未来列表
我试图返回一个可完成的未来列表,如下所示, List<CompletableFuture<Optional<ModelObject>>> collect = listOfModel. stream(). map(modelObject -> CompletableFuture.sup...