gpt4 book ai didi

java - 在 Vertx 中实现扇出

转载 作者:行者123 更新时间:2023-12-02 10:35:46 25 4
gpt4 key购买 nike

我正在实现一个 http 服务器,它使用 vertx 版本 3.5.4 将工作分散到 http 客户端。

服务器接收工作并将其异步分发给一群客户端。但是,我需要阻塞请求线程,直到所有结果都到达。

在纯java世界中,我会做类似的事情:

CountdownLatch latch = new CountdownLatch( 3 ); 
executor.submit( new Request(client1) );
executor.submit( new Request(client2) );
executor.submit( new Request(client3) );
latch.await(); // block the request thread

//In callback thread from clients
latch.countdown();

但是,在 vertx 中,我无法阻止主事件循环线程。阻止初始请求线程的推荐方法是什么?

谢谢

最佳答案

你是对的,你不能阻塞事件循环。在异步世界中,您需要组合不同的结果并最终回复请求。

看看Concurrent composition文档部分。

关于java - 在 Vertx 中实现扇出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53305929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com